asp.net MVC中form提交和控制器接受form提交过来的数据

MVC中form提交和在控制器中怎样接受

1.cshtml页面form提交

asp.net MVC中form提交和控制器接受form提交过来的数据_第1张图片
2.控制器处理表单提交数据4种方式
方法1:使用传统的Request请求取值
[HttpPost]
public ActionResult AddNews()
{
       string a= Request[" text1"] ;
       string b= Request[" text2"] ;
}
方法2:Action参数名与表单元素name值一一对应
[HttpPost]
public ActionResult AddNews(string  text1,string   text2 )
{
       string a= text1 ;
       string b= text2 ;
}
方法3:从MVC封装的FormCollection容器中读取
[HttpPost]
public ActionResult AddNews( FormCollection form)
{
    string a=
form[" text1"];
    string b=
form[" text2"];
}

方法4:使用实体作为Action参数传入,前提是提交的表单元素名称与实体属性名称一一对应
[HttpPost]
public ActionResult AddNews(userModel user)
{
    string a=
user.text1;
    string b=
user. text2;
}

你可能感兴趣的:(asp.net MVC中form提交和控制器接受form提交过来的数据)