0

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?

George Duckett
  • 31,770
  • 9
  • 95
  • 162
  • Are you displaying the dates in different culture/format? – VJAI Jul 16 '12 at 10:16
  • I've just checked the input element that is generated and it is in american date format (Despite this PC and all code set as British date format). Make that an answer and I'll accept. – George Duckett Jul 16 '12 at 10:21

1 Answers1

1

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.

Community
  • 1
  • 1
VJAI
  • 32,167
  • 23
  • 102
  • 164