日期:2014-05-17  浏览次数:20422 次

asp.net MVC的 C处 怎样获得 V页面文本框里面的值啊
public ActionResult IndexTest()
  {
  String s = Request.Form["testIndex"];

  return View();
  }
我在V页面有个文本框名为testIndex 为什么我我在这里取不出它的值啊

------解决方案--------------------
public ActionResult IndexTest(string testIndex)
{

}
------解决方案--------------------
public ActionResult Search(string q)
{
var albums = storeDB.Albums
.Include(“Artist”)
.Where(a => a.Title.Contains(q) || q == null)
.Take(10);
return View(albums);
}
Notice how the Searchaction expects to receive a string parameter named q. The MVC framework automatically finds this value in the query string, when the name qis present, and also finds the value in posted form values if you made your search form issue a POST instead of a GET. 

摘自Professional ASP.NET MVC 3

也就是说如果你的controller方法有入参,MVC framework会自动帮你从get或者post的表单数据中进行匹配,然后把参数传进来。不需要调用request对象的方法