【发布时间】:2015-10-02 00:21:39
【问题描述】:
我有一个强类型视图,我在其中传递几个属性的编辑器,例如。
public class BookingModel
{
public FirstPropertyModel FirstProperty { get; set; }
public SecondPropertyModel SecondProperty { get; set; }
public ThirdPropertyModel ThirdProperty { get; set; }
}
@model MyWebsite.Models.BookingModel
@using (Html.BeginForm("Order", "Booking", FormMethod.Post, new { @id = "order_summary" }))
{
@Html.EditorFor(model => model.FirstProperty, "_FirstProperty")
@Html.EditorFor(model => model.SecondProperty, "_SecondProperty")
@Html.EditorFor(model => model.ThirdProperty, "_ThirdProperty")
<input type="submit" id="btnOrder" value="Order" />
}
所有属性对象都很好地传递给动作,但一个属性(第一)作为空值出现。
它们都在 EditorTemplates 中,它们的视图也是强类型 - 使用它们自己的模型。
知道为什么会这样吗?
【问题讨论】:
-
模板
_FirstProperty等是如何定义的? -
我在属性视图上显示某些模型属性时遇到了问题,因此修复了属性空问题后已修复。感谢您的回复
-
如果可能,请添加您自己的描述修复的答案(然后接受它)。这使将来遇到此问题的开发人员可以了解解决方案,并在适用的情况下使用它。
标签: asp.net-mvc model editorfor strongly-typed-view editortemplates