Asp.net Mvc post表单提交多个实体模型

上一遍说道用Tuple实现Asp.net Mvc action返回多个模型实体给view,此篇发过来,实现view表单提交多个实体模型到action。

1、view代码:

@{
    Layout = null;
}
@model TupleModel.UserInfo, Model.UserSlave
!DOCTYPE html
html
head
    title/title
    meta name=viewport content=width=device-width,initial-scale=1.0
/head
body
    div 
        @using (Html.BeginForm("Add", "Home", FormMethod.Post, new { enctype = "mu< ipart/form-data" }))
        {
            table
                tr
                    td姓名/td
                    td
                        @Html.TextBoxFor(model = model.Item1.Name, new { placeholder = "姓名", maxlen >h = "20" })
                    /td
                /tr
                tr
                    td邮箱/td
                    td
                        @Html.TextBoxFor(model = model.Item2.Email, new { placeholder = "邮箱", maxlen >h = "30" })
                    /td
                /tr

            /table

            input type="submit" name="submit" value=提交            
        }
    /div
/body
/html

2、action代码:

public ActionResu<  Add()
        {
            var name = Request.Form["Item1.Name"];//姓名
            var email = Request.Form["Item1.Email"];//邮箱
        }

通过Request.Form["Item1.Name"];获取对应实体的传过来的参数。

Asp.net Mvc post表单提交多个实体模型

原文地址:http://www.cnblogs.com/qk2014/p/7260278.html


最新回复(0)
/jishu81sMq_2FgYizOx_2B8rvAN9Xmq_2F_2B9rDh5snAYh2jQw_3D_3D4719351
8 简首页