<?xml version="1.0" encoding="UTF-8"?> 1. 用Html.BeginForm(ActionName,ControllerName,Post)来实现controller-action的路由,
2. Form里的每个input的name值统一,比如都命名为commandName, 每个input的value设为不同值。
3. 更改Action处理方法的参数, 添加一个参数为commandName,则commandName的值为input设置的value。
例:
@using (Html.BeginForm("SaveRisDBConfig", "Home", FormMethod.Post)) { <div class="display-field"> @Html.LabelFor(model => model.DBHost) </div><div class="editor-field"> @Html.EditorFor(model => model.DBHost) @Html.ValidationMessageFor(model => model.DBHost) </div> <input type="submit" value="保存" name="commandName"/> <input type="submit" value="连接测试" name="commandName"/> }
[HttpPost] public ActionResult SaveRisDBConfig(string commandName)
{
switch (commandName)
{ case "保存":
....
case "连接测试":
...
default:
break; }
}
转载于:https://blog.51cto.com/muzizongheng/1333050