ASP.NET MVC表单post

Name:

我的表单在上面,如何检索控制器中的值?

非常感谢提前! 由于MVC的不同预览被发布和不同,很难找到合适的材料。

这适用于ASP.Net MVC Beta。

  public ActionResult Add( string name ) { .... } or public ActionResult Add( FormCollection form ) { string name = form["Name"]; } or public ActionResult Add( [Bind(Prefix="")]Villa villa ) { villa.Name ... } 

你尝试过这样的事吗? 伪…

 public class VillaController : Controller { public ActionResult Add(string name) { // Code... } } 

它属于您定义的url路由。

在您的情况下,表单正在寻找名为“Villa”的控制器,其中的操作名为“Add”。

也许您应该阅读ScottGu的博客文章: http : //weblogs.asp.net/scottgu/archive/2008/09/02/asp-net-mvc-preview-5-and-form-posting-scenarios.aspx