装订形式值的复杂类型 [英] Binding form values to a complex type

查看:114
本文介绍了装订形式值的复杂类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用MVC模式,而现在,并已获得精细,但是我已经得到了完全卡住了​​。

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)

表格确有其收藏价值 CallAppointmentDate 所以我的理解是,它应适当填充值

The Form does have the value CallAppointmentDate in its collection so my understanding it that it should populate the value appropriately.

我已经尝试了许多排列组合,包括更改名称 PartOnOrder.CallAppointmentDate ,设定的ID以及名称,添加属性,各个参数并没有什么作品

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.

我在做什么错了?

推荐答案

默认模型绑定确实基于服务器的当前文化的结合/验证工作。如果你想要做的日期时间绑定/验证基于不同的文化,你必须写的自定义模型粘合剂

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.

这篇关于装订形式值的复杂类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆