Table of Contents

Class ButtonViewModel

Namespace
Dynamicweb.Frontend
Assembly
Dynamicweb.dll

The ButtonViewModel class is a specialized view model for handling CTA buttons. It extends from the ViewModelBase class.

public sealed class ButtonViewModel : ViewModelBase
Inheritance
ButtonViewModel
Inherited Members

Examples

Here's how you can use the ButtonViewModel in a Razor view:

@if (Model.Item.TryGetButton("SecondButton", out ButtonViewModel secondButton)) {
    <a href="@secondButton.Link.Url" class="btn btn-@secondButton.Style" data-dw-button="@secondButton.Style">@secondButton.Label</a>
}

Properties

Label

Gets or sets the label of the button, e.g. "Read more".

public string? Label { get; set; }

Property Value

string

The label.

Gets or sets the link for the button if specified.

public LinkViewModel? Link { get; set; }

Property Value

LinkViewModel

The link for the button.

Style

Gets or sets the style of the button.

public string? Style { get; set; }

Property Value

string

The style of the button.

Remarks

One of these 5 styles (cannot be changed):

  • "primary"
  • "outline-primary"
  • "secondary"
  • "outline-secondary"
  • "link"
To top