Guest User

Untitled

a guest
Jan 19th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. public class RegisterModel
  2. {
  3. <!-- some properties -->
  4.  
  5. [Required]
  6. public Dictionary<DayOfWeek, bool> DaysAtWork { get; set; }
  7.  
  8. public RegisterModel()
  9. {
  10. DaysAtWork = new Dictionary<DayOfWeek, bool>
  11. {
  12. {DayOfWeek.Monday, true},
  13. {DayOfWeek.Tuesday, true},
  14. {DayOfWeek.Wednesday, true},
  15. {DayOfWeek.Thursday, true},
  16. {DayOfWeek.Friday, true}
  17. };
  18. }
  19. }
  20.  
  21. public ActionResult Register()
  22. {
  23. var model = new RegisterModel();
  24.  
  25. return View(model);
  26. }
  27.  
  28. [HttpPost]
  29. public ActionResult Register(RegisterModel model)
  30. {
  31. <!-- and at these point in model state property for DaysAtWork
  32. Dictionary is null and the whole model is invalid - and property in model
  33. parameter is also null -->
  34. if (ModelState.IsValid)
  35. {
  36. <!-- some logic here -->
  37. }
  38. return View(model);
  39. }
  40.  
  41. <!-- some code -->
  42. @using (Html.BeginForm()) {
  43. @Html.ValidationSummary(true, "Account creation was unsuccessful. Please correct the errors and try again.")
  44. <div>
  45. <fieldset>
  46. <legend>Account Information</legend>
  47.  
  48. <div>Days at work</div>
  49.  
  50. <div>
  51. Monday @Html.CheckBoxFor(m => m.DaysAtWork[DayOfWeek.Monday])
  52. </div>
  53. <div>
  54. Tuesday @Html.CheckBoxFor(m => m.DaysAtWork[DayOfWeek.Tuesday])
  55. </div>
  56. <div>
  57. Wednesday @Html.CheckBoxFor(m => m.DaysAtWork[DayOfWeek.Wednesday])
  58. </div>
  59. <div>
  60. Thursday @Html.CheckBoxFor(m => m.DaysAtWork[DayOfWeek.Thursday])
  61. </div>
  62. <div>
  63. Friday @Html.CheckBoxFor(m => m.DaysAtWork[DayOfWeek.Friday])
  64. </div>
  65.  
  66.  
  67. <p>
  68. <input type="submit" value="Register" />
  69. </p>
  70. </fieldset>
  71. </div>
  72. }
  73.  
  74. public Week(){
  75. public int Id;
  76. public int AccountId;
  77. public bool Monday;
  78. public bool ...;
  79. public bool Friday;
  80. }
Add Comment
Please, Sign In to add comment