Table of Contents

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

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

model AddressListViewModel

The AddressListViewModel instance from the list template. May be null.

pageId int

The ID of the page hosting the UserAddresses module (typically Pageview.Page.ID).

addressId int

The ID of the address to edit.

Returns

string

A URL like /?ID={pageId}&Cmd=EditAddress&AddressId={addressId} when model is not null; otherwise null.

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.

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

model AddressListViewModel

The AddressListViewModel instance from the list template. May be null.

pageId int

The ID of the page hosting the UserAddresses module (typically Pageview.Page.ID).

Returns

string

A URL like /?ID={pageId}&Cmd=EditAddress&AddressId=0 when model is not null; otherwise null.

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.

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

model AddressListViewModel

The AddressListViewModel instance from the list template. May be null.

pageId int

The ID of the page hosting the UserAddresses module (typically Pageview.Page.ID).

addressId int

The ID of the address to delete.

Returns

string

A URL like /?ID={pageId}&Cmd=DeleteAddress&AddressId={addressId} when model is not null; otherwise null.

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.

Gets a POST action URL for marking the current address as default (?Cmd=SetDefault).

public static string? SetDefaultAddressLink(this UserAddressViewModel model, int pageId)

Parameters

model UserAddressViewModel

The UserAddressViewModel instance from the edit template. May be null.

pageId int

The 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} when model is not null; otherwise null.

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.

See Also

To top