Not getting updates in MVC View following a post method
Hi,
Here’s my controller code:
public ActionResult Search()
{
ForecastManagementViewModel viewModel = new ForecastManagementViewModel();
viewModel.JobDate = System.DateTime.Now;
return View(viewModel);
}
[HttpPost]
public ActionResult Search(ForecastManagementViewModelPost model)
{
ForecastManagementViewModel viewModel = new ForecastManagementViewModel();
viewModel.JobDate = model.JobDate.AddDays(20);
return View(viewModel);
}
The problem is that when the new view is returned it doesn’t contain the updated date value. (By the way, there’s a jquery EditorTemplate behind this DateTime type).
Here’s a bit of the view code:
<% using (Html.BeginForm())
{ %>
<fieldset>
<legend>Search Criteria</legend>
<div class="divFirstColumn">
<div><%= Html.LabelFor(m => m.JobDate) %></div>
<%= Html.EditorFor(m => m.JobDate) %>
</div>
</fieldset>
<% } %>
Any ideas where I might be going wrong. I’m using MVC2 under Visual Studio 2008 SP1.
Cheers,
J Dubs.
Could be a form mismatch issue… could you check the ID on the client side by doing view source to make sure it will properly hook up to the model when posting? Also, I would check, using a breakpoint in the post, the form collection to see what the key is on the server-side also. THe form collection is available as a property of the controller too.