Class FieldOptionValueViewModel
- Namespace
- Dynamicweb.Ecommerce.ProductCatalog
- Assembly
- Dynamicweb.Ecommerce.dll
Represents one selected option of a list-type product field (e.g. one entry in a size, colour, or material field).
public class FieldOptionValueViewModel : FillableViewModelBase
- Inheritance
-
FieldOptionValueViewModel
- Inherited Members
- Extension Methods
Remarks
When a FieldValueViewModel has Type == "List", its Value property holds a
List<T> of FieldOptionValueViewModel — one entry
per selected option. Single-select fields still use a list with one element.
Use TryGetColor(FieldOptionValueViewModel, out ColorViewModel?) to check whether Value is a hex colour and get a ColorViewModel for rendering colour swatches.
Typical Razor template usage — render a list field's selected options:
@foreach (var option in field.GetList())
{
@if (option.TryGetColor(out var color))
{
<span style="background:@color.Hex" class="swatch"></span>
}
else
{
<span>@option.Name</span>
}
}
Properties
Image
Gets or sets the relative path to an image associated with the option (e.g. a swatch image). May be null or empty if no image is configured for this option.
public string Image { get; set; }
Property Value
Name
Gets or sets the display name of the selected option (e.g. "Red", "Large").
Use this as the human-readable label in the template.
public string Name { get; set; }
Property Value
Value
Gets or sets the raw stored value of the option (e.g. a hex colour code "#FF0000" or a size code "L").
Use TryGetColor(FieldOptionValueViewModel, out ColorViewModel?) to check whether this is a colour.
public string Value { get; set; }