.net mvc中数据传递的常见四个方法:
public ActionResult sayHello() //不带参数直接返回 ,URL地址中只要有 控制器/方法名,即可
{
return Content("hello");
}
public ActionResult sayHello2() //四中接收数据的方法
{
string name = Request.QueryString["name"];//用url地址获取
name = Request.Form["name"];//表单提交的方法
HttpCookie hc= Request.Cookies["name"];//cookie 的方法
var s = HttpContext.Session.Getstring("");
HttpContext.Session.RemoveAll();
return Content("hello " + name);
}
public ActionResult sayHello3(string name) //在url地址中用参数的形式放回数据
{
return Content("hello " + name);
}
public ActionResult sayHello4(ncc md) //在url地址中用属性传递参数,其中 ncc 是类名
{
return Content("hello " + md.heigh);
}