ASP.NET MVC 获取表单数据

public class Person

{

public string Name{get;set;}

public string Phone{get;set;}

}

view层

@model Model.Person

@{
    ViewBag.Title = "Add";
}

@using (Html.BeginForm("doAdd","person",FormMethod.Post) {

}

1、通过request.form获取表单数据

public ActionResult doAdd()
        {
            Person person = new Person();
            person.Name= Request.Form["Name"];
            person.Phone= Request.Form["Phone"];

personService.add(person);
            return View("Index");
        }

2、通过FormCollection获取表单数据

public ActionResult doAdd(FormCollection form)
        {
            Person person = new Person();
            person.Name= form["Name"];
            person.Phone= form["Phone"];

personService.add(person);
            return View("Index");
        }

3、通过Person对象获取

public ActionResult doAdd(Person person)
        {

personService.add(person);
            return View("Index");
        }

上一篇:JavaScript是如何工作的:编写自己的Web开发框架 + React及其虚拟DOM原理


下一篇:android aysncTask面试解析