Binding form values to a complex type

丶灬走出姿态 提交于 2019-12-12 05:38:14

问题


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?


回答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.



来源:https://stackoverflow.com/questions/11502180/binding-form-values-to-a-complex-type

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!