ias*_*ons 6 asp.net-mvc model-binders
我有一个表格需要填充2个模型.通常我在表单post post上使用ModelBinderAttribute,即
[Authorize]
[AcceptVerbs("POST")]
public ActionResult Add([GigBinderAttribute]Gig gig, FormCollection formCollection)
{
///Do stuff
}
Run Code Online (Sandbox Code Playgroud)
在我的表单中,字段的名称与模型属性相同...
但是在这种情况下,我有2个不同的模型需要填充.
我该怎么做呢?有任何想法吗?可能吗?
实际上......最好的方法是这样做:
public ActionResult Add([GigBinderAttribute]Gig gig, [FileModelBinderAttribute]File file) {
Run Code Online (Sandbox Code Playgroud)
}
您可以使用多个属性!
在这种情况下,我倾向于使用单一模型类型来包含所涉及的各种模型:
class AddModel
{
public Gig GigModel {get; set;}
public OtherType OtherModel {get; set;}
}
Run Code Online (Sandbox Code Playgroud)
......并绑定它.
| 归档时间: |
|
| 查看次数: |
5915 次 |
| 最近记录: |