
kevin hudson
Courses Plus Student 11,561 PointsNeed clarification
when adding the ModelState the instructor uses first capitalization that matches the ViewBag values but the ModelState is lowercase as the same as the method parameters. Why does this work both ways? My code I put in lowercase with the exception of the date argument
public ActionResult Add(DateTime? date, int? activityId, double? duration,
Entry.IntensityLevel? intensity, bool? exclude, string notes)
{
ViewBag.Date = ModelState["Date"].Value.AttemptedValue;
ViewBag.ActivityId = ModelState["activityId"].Value.AttemptedValue;
ViewBag.Duration = ModelState["duration"].Value.AttemptedValue;
ViewBag.Intensity = ModelState["intensity"].Value.AttemptedValue;
ViewBag.Exclude = ModelState["exclude"].Value.AttemptedValue;
ViewBag.Notes = ModelState["notes"].Value.AttemptedValue;
return View();
}
2 Answers

Allan Clark
10,806 PointsThe matching for the string passed in is not case sensitive. You would be able to use ModelState["duRAtiON"].Value.AttemptedValue as long as the spelling is correct. I can't say as to why it is like this, maybe for performance, or reduce complexity, would have to ask Microsoft haha.
Hope this helps Happy Coding!

kevin hudson
Courses Plus Student 11,561 PointsThanks Allen. It would be better to mention this in the video at some point or keep the naming conventions the same.