【发布时间】:2015-04-10 19:52:15
【问题描述】:
我一直在寻找一种方法来发布包含其他模型的模型的所有信息,我相信我可以将对象发送到我的视图,然后从我看过的 50 个示例中取出并可以渲染一切都很好。
这是我所说的名为 Equipment 的模型。
public int id { get; set; }
public String name { get; set; }
public ManufacturerItem manufacturerItem { get; set; }
public EquipmentType equipmentType { get; set; }
public SupportItem supportItem{ get; set; }
public Placement placement{ get; set; }
public Boolean status { get; set; }
public DateTime endOfLife{ get; set; }
public String notes{ get; set; }
public Purchase purchase{ get; set; }
public Boolean mes{ get; set; }
public DateTime reviewedDate{ get; set; }
根据我读过的大量示例,我知道我可以像这样呈现这些:
@Html.EditorFor(model => model.name)
@Html.EditorFor(model => model.manufacturerItem.model.name)
在其他研究中,我确实偶然发现了building forms for deep View Model graphs in ASP.NET MVC,我可能会考虑使用它,但在 MVC 中发布了 2 天。我正在使用 MVC 5。所以我不知道今天的相关性。
假设我有另一个名为 Book 的模型,带有 {id, Title, Author},您可以编辑书名和作者。现在在这个模型中,在编辑时,我的控制器可能是这样的:
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Edit([Bind(Include="ID,Title,Author)"] Book book)
{ ... -insert code- ...}
放弃这个想法,设备模型的控制器方法签名是什么?我是否将其他对象作为它们自己的类型包含在内?
我没有使用 EF 或 linq-to-sql,因为我必须使用存储过程。因此,我希望将所有这些信息整齐地打包并传递到存储库,该存储库将负责参数分配和存储过程的调用。
【问题讨论】:
标签: c# controller asp.net-mvc-5 asp.net-routing