话不多说,直接上代码。
1、第一种接受数据方式
public ActionResult GetDate(string name,string sex,string address)
{//断点
string str = name + "&&" + sex + "&&" + address;
return Content(str);
}
2、第二种接受数据方式
public ActionResult getFormCollection(FormCollection form)//实例
{ //通过FormCollection提交的数据,只能通过post
string name = form["name"];
string sex = form["sex"];
string address = form["address"];
string str = name + "%" + sex + "&" + address;
return Content(str);
}
3、第三种接受数据方式
public ActionResult postDateByRequest()
{
string name = Request.Form["name"];
string sex = Request.Form["sex"];
string address = Request.Form["address"];
string str = name + "&" + sex + "&" + address;
return Content(str);
}
4、第四种接受数据方式
public ActionResult EntityClass(Person person)
{
string name = person.name;
string sex = person.sex;
string address = person.address;
string str = name + "&" + sex + "&" + address;
return Json(str, JsonRequestBehavior.AllowGet);
}
public class Person
{
public string name { get; set; }
public string sex { get; set; }
public string address { get; set; }
}
如果使用get请求,那么只能使用第一种和第四种接收数据的方式,POST请求则四种都可以



