加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net-mvc – ASP.NET MVC – 表单和模型绑定器中的多个模型

发布时间:2020-12-15 18:56:59 所属栏目:asp.Net 来源:网络整理
导读:我有一个表格需要填充2个模型.通常我在表单post post上使用ModelBinderAttribute,即 [Authorize] [AcceptVerbs("POST")] public ActionResult Add([GigBinderAttribute]Gig gig,FormCollection formCollection) { ///Do stuff } 在我的表单中,字段的名称与模
我有一个表格需要填充2个模型.通常我在表单post post上使用ModelBinderAttribute,即
[Authorize]
    [AcceptVerbs("POST")]
    public ActionResult Add([GigBinderAttribute]Gig gig,FormCollection formCollection)
    {
       ///Do stuff
    }

在我的表单中,字段的名称与模型属性相同…

但是在这种情况下,我有2个不同的模型需要填充.

我该怎么做呢?有任何想法吗?可能吗?

解决方法

实际上……最好的方法是这样做:
public ActionResult Add([GigBinderAttribute]Gig gig,[FileModelBinderAttribute]File file) {

}

您可以使用多个属性!

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读