如何将值从视图传递给控制器

Ste*_*ffi 3 c# asp.net asp.net-mvc-3

我有个问题.

我需要将值传递C# and MVC3给控制器,但我不知道如何.

我认为的代码是:

@html.textbox("Name"); 
<input value="Envoyer" type="submit">
Run Code Online (Sandbox Code Playgroud)

我怎样才能获得name控制器的价值?

谢谢

Jac*_*tti 6

将其包装在一个表单中,并有一个提交按钮,以调用您的操作方法.

<% using (Html.BeginForm("MethodName", "Home", FormMethod.Post)) {%>
     <% Html.Textbox("Name") %> 
     <input value="Envoyer" type="submit" />
<% } %>



[HttpPost]
public ActionResult MethodName(FormCollection col)
{
    string name = col["Name"];
}
Run Code Online (Sandbox Code Playgroud)


tug*_*erk 6

还有另一种方式.

[HttpPost]
public ActionResult Index() {

    string name = Request["name"];
}
Run Code Online (Sandbox Code Playgroud)