Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class ProductVM
- // This is the main viewmodel for the view
- {
- public int Id { get; set; }
- public string Title { get; set; }
- public List<ProductPropertyVM> Properties { get; set; }
- }
- public class ProductPropertyVM
- // This represents a property a product can have, e.g. "Colour".
- {
- public int Id { get; set; }
- public string Label { get; set; }
- [Required]
- public int? SelectedRadioOption { get; set; }
- public List<ProductPropertyOptionVM> Options { get; set; }
- }
- public class ProductPropertyOptionVM
- // This represents options a property can have, e.g. "Red", "Green", "Blue".
- {
- public int Id { get; set; }
- public string Value { get; set; }
- }
- for (int i = 0; i < Model.Properties.Count(); i++)
- {
- <strong>@Model.Properties[i].Label</strong><br />
- @if (Model.Properties[i].Options != null)
- {
- @foreach (var option in Model.Properties[i].Options)
- {
- @Html.RadioButtonFor(m => m.Properties[i].SelectedRadioOption, option.Id, new { id = "" })
- <span>@option.Value</span>
- <br />
- }
- @Html.ValidationMessageFor(m => m.Properties[i].SelectedRadioOption)
- }
- }
Add Comment
Please, Sign In to add comment