ASP.NET MVC 获取表单数据

 

(2012-10-09 10:00:37)
标签:

mvc

form

it

分类: C#

实体类: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()
        {
            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");
        }

posted @ 2012-10-11 09:08  哪啊哪啊神去村  阅读(452)  评论(0编辑  收藏  举报