ASP.NET MVC 获取表单数据
实体类:person
public class Person
{
public string Name{get;set;}
public string Phone{get;set;}
}
view层
@model Model.Person
@{
ViewBag.Title = "Add";
}
Add
@using (Html.BeginForm("doAdd","person",FormMethod.Post) {
@Html.LabelFor(model=>model.Name)
@Html.EditorFor(model => model.Name)
@Html.LabelFor(model=>model.Phone)
@Html.EditorFor(model=>model.Phone)
}
1、通过request.form获取表单数据
public ActionResult doAdd()
{
Personperson = new Person();
person.Name=Request.Form["Name"];
person.Phone= Request.Form["Phone"];
personService.add(person);
returnView("Index");
}
2、通过FormCollection获取表单数据
public ActionResult doAdd(FormCollectionform)
{
Personperson = new Person();
person.Name=form["Name"];
person.Phone= form["Phone"];
personService.add(person);
returnView("Index");
}
3、通过Person对象获取
public ActionResult doAdd(Person person)
{
personService.add(person);
returnView("Index");
}
http://blog.sina.com.cn/s/blog_64008ed70101bdqd.html