ASP.NET MVC表单提交

10
   <form action="/Villa/Add" method="post">
    <table>
        <tr>
            <td>
                Name:
            </td>
            <td>
                <%= Html.TextBox("name") %>
                <%= Html.ValidationMessage("Name") %>
            </td>
        </tr>
                <tr>
                <td>
                </td>
                <td>
                    <input type="submit" value="Add" />
                </td>
            </tr>
        </table>
        </form>

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

非常感谢!由于发布了不同的MVC预览版并且它们不同,很难找到正确的材料。

3个回答

21

这适用于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 ...
 }

5

您是否尝试过像这样的方法?伪代码...

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

1

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接