Guest User

Untitled

a guest
Apr 19th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. public class ProductVM
  2. // This is the main viewmodel for the view
  3. {
  4. public int Id { get; set; }
  5. public string Title { get; set; }
  6. public List<ProductPropertyVM> Properties { get; set; }
  7. }
  8.  
  9. public class ProductPropertyVM
  10. // This represents a property a product can have, e.g. "Colour".
  11. {
  12. public int Id { get; set; }
  13. public string Label { get; set; }
  14. [Required]
  15. public int? SelectedRadioOption { get; set; }
  16. public List<ProductPropertyOptionVM> Options { get; set; }
  17. }
  18.  
  19. public class ProductPropertyOptionVM
  20. // This represents options a property can have, e.g. "Red", "Green", "Blue".
  21. {
  22. public int Id { get; set; }
  23. public string Value { get; set; }
  24. }
  25.  
  26. for (int i = 0; i < Model.Properties.Count(); i++)
  27. {
  28. <strong>@Model.Properties[i].Label</strong><br />
  29. @if (Model.Properties[i].Options != null)
  30. {
  31. @foreach (var option in Model.Properties[i].Options)
  32. {
  33. @Html.RadioButtonFor(m => m.Properties[i].SelectedRadioOption, option.Id, new { id = "" })
  34. <span>@option.Value</span>
  35. <br />
  36. }
  37. @Html.ValidationMessageFor(m => m.Properties[i].SelectedRadioOption)
  38. }
  39. }
Add Comment
Please, Sign In to add comment