I've used the MVC pattern for a while now and have been getting on fine, however I've got totally stuck.
I have a view which shows a collection of complex objects, with a partial view as follows:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<ThreeSixtyScheduling.Areas.Products.Models.PartsOnOrderModel+PartOnOrder>" %>
<tr>
<% using (Html.BeginForm("UpdateStockDueDate", "PartsOnOrder", FormMethod.Post))
{ %>
<td><input type="hidden" name="CallAppointmentDate" value="<%= Model.CallAppointmentDate %>" /><%= Html.DisplayFor(m => m.CallAppointmentDate)%></td>
<td><%= Html.HiddenFor(m => m.OrderNumber)%><%= Html.DisplayFor(m => m.OrderNumber)%></td>
<td><%= Html.HiddenFor(m => m.JobNumber)%><%= Html.DisplayFor(m => m.JobNumber)%></td>
<td><%= Html.HiddenFor(m => m.Part)%><%= Html.DisplayFor(m => m.Part)%></td>
<td><%= Html.HiddenFor(m => m.Quantity)%><%= Html.DisplayFor(m => m.Quantity)%></td>
<td><%= Html.EditorFor(m => m.StockDueDate)%></td>
<td><button type="submit">Save</button></td>
<% } %>
</tr>
I have a controller action that takes the complex object as its parameter:
public ActionResult UpdateStockDueDate(PartsOnOrderModel.PartOnOrder PartOnOrder)
The Form
does have the value CallAppointmentDate
in its collection so my understanding it that it should populate the value appropriately.
I've tried MANY permutations, including changing the name to PartOnOrder.CallAppointmentDate
, setting the IDs as well as the name, adding the properties as individual parameters and nothing works.
What am I doing wrong?
The Default Model Binder does the binding/validation work based upon the current culture of the server. If you want to do the datetime binding/validation based upon a different culture you have to write a custom model binder.