Class AddressListViewModelExtensions
- Namespace
- Dynamicweb.Users.Frontend.UserAddresses
- Assembly
- Dynamicweb.Users.dll
Extension methods for AddressListViewModel.
public static class AddressListViewModelExtensions
- Inheritance
-
AddressListViewModelExtensions
- Inherited Members
Examples
Razor template usage (list):
@inherits ViewModelTemplate<Dynamicweb.Frontend.AddressListViewModel> @using Dynamicweb.Users.Frontend.UserAddresses
@{ var newAddress = Model.GetCreateNewAddressLink(Pageview.Page.ID); // "/?ID=123&Cmd=EditAddress&AddressId=0" }
<a href="@newAddress" class="btn">New address</a>
@foreach (var a in Model.Addresses) { var editLink = Model.GetAddressLink(Pageview.Page.ID, a.Id); // "/?ID=123&Cmd=EditAddress&AddressId=45" var deleteLink = Model.GetDeleteAddressLink(Pageview.Page.ID, a.Id); // "/?ID=123&Cmd=DeleteAddress&AddressId=45" <a href="@editLink">Edit</a> <form method="post" action="@deleteLink" class="inline"><button type="submit">Delete</button></form> }
Remarks
These helpers simplify building links from AddressListViewModel and UserAddressViewModel. The most common usage is calling GetCreateNewAddressLink(AddressListViewModel, int) to open a blank edit form, GetAddressLink(AddressListViewModel, int, int) to edit a specific address, and GetDeleteAddressLink(AddressListViewModel, int, int) to post a delete from the list. From the edit view, use SetDefaultAddressLink(UserAddressViewModel, int) to mark an address as default.
Methods
GetAddressLink(AddressListViewModel, int, int)
Gets a link to open the edit view for a specific address (?Cmd=EditAddress).
public static string? GetAddressLink(this AddressListViewModel model, int pageId, int addressId)
Parameters
modelAddressListViewModelThe AddressListViewModel instance from the list template. May be
null.pageIdintThe ID of the page hosting the UserAddresses module (typically
Pageview.Page.ID).addressIdintThe ID of the address to edit.
Returns
- string
A URL like
/?ID={pageId}&Cmd=EditAddress&AddressId={addressId}whenmodelis notnull; otherwisenull.
Remarks
This is a safe accessor — it returns null if the model is null. Use it to navigate from a list row to the edit page.
GetCreateNewAddressLink(AddressListViewModel, int)
Gets a link to open the edit view with a new, empty address (AddressId=0).
public static string? GetCreateNewAddressLink(this AddressListViewModel model, int pageId)
Parameters
modelAddressListViewModelThe AddressListViewModel instance from the list template. May be
null.pageIdintThe ID of the page hosting the UserAddresses module (typically
Pageview.Page.ID).
Returns
- string
A URL like
/?ID={pageId}&Cmd=EditAddress&AddressId=0whenmodelis notnull; otherwisenull.
Remarks
This is a safe accessor — it returns null if the model itself is null. Use it to render a
“New address” link or button; the target page will show the edit form for creating a new address.
GetDeleteAddressLink(AddressListViewModel, int, int)
Gets a POST action URL for deleting an address from the list (?Cmd=DeleteAddress).
public static string? GetDeleteAddressLink(this AddressListViewModel model, int pageId, int addressId)
Parameters
modelAddressListViewModelThe AddressListViewModel instance from the list template. May be
null.pageIdintThe ID of the page hosting the UserAddresses module (typically
Pageview.Page.ID).addressIdintThe ID of the address to delete.
Returns
- string
A URL like
/?ID={pageId}&Cmd=DeleteAddress&AddressId={addressId}whenmodelis notnull; otherwisenull.
Remarks
Prefer using this link with a method="post" form for destructive actions. This is a safe accessor — it returns
null if the model is null.
SetDefaultAddressLink(UserAddressViewModel, int)
Gets a POST action URL for marking the current address as default (?Cmd=SetDefault).
public static string? SetDefaultAddressLink(this UserAddressViewModel model, int pageId)
Parameters
modelUserAddressViewModelThe UserAddressViewModel instance from the edit template. May be
null.pageIdintThe ID of the page hosting the UserAddresses module (typically
Pageview.Page.ID).
Returns
- string
A URL like
/?ID={pageId}&Cmd=SetDefault&AddressId={model.Address.Id}whenmodelis notnull; otherwisenull.
Remarks
Use this with a small POST form (e.g., a “Set as default” button). The module will clear any previous default
in the same scope/kind and set this one. This is a safe accessor — it returns null if the model is null.