MVC如何在不使用模型的情况下发布表单

kay*_*yze 1 forms model-view-controller

我想知道如何在不使用模型绑定到视图的情况下在MVC 4中汇总表格。

可以请一个人如何取消吗?以及如何在控制器中使用该表格?

Tim*_*mes 6

无需任何模型绑定即可使用表单非常容易。

简单设置您使用@using(Html.BeginForm()){ ... }HTML还是纯HTML。

<form id="myForm" action="/ControllerName/ActionName" method="Post">

    <input type="text" name="foo" value="FOOOO" />
    <input type="text" name="bar" value="Baaaar" />
    <button type="submit">Submit</button>

</form>
Run Code Online (Sandbox Code Playgroud)

将其发布到ActionResult时,只需将操作结果设置为接受一个名为foo的字符串值和一个名为bar的字符串值

[HttpPost]
public ActionResult ActionName(string foo, string bar){
    // your code here
    return View();
}
Run Code Online (Sandbox Code Playgroud)