In my ASP.net MVC app I have a view that looks like this:
...
<%=Html.TextBox(\"due\")%>
...
I am usi
MVC4 EF5 View I was trying to preload a field with today's date then pass it to the view for approval.
ViewModel.SEnd = DateTime.Now //preload todays date
return View(ViewModel) //pass to view
In the view, my first code allowed an edit:
@Html.EditedFor(item.SEnd) //allow edit
Later I changed it to just display the date, the user cannot change it but the submit triggers the controller savechanges
@Html.DisplyFor(item.SEnd) //show no edit
When I changed to DisplayFor I needed to add this to ensure the preloaded value was passed back to the controller. I also need to add HiddenFor's for every field in the viewmodel.
@Html.HiddenFor(model => model.SEnd) //preserve value for passback.
Beginners stuff but it took a while to work this out.