ASP.Net MVC实现一个表单多个submit

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;
     }
}
posted @ 2013-07-03 16:47  muzizongheng  阅读(715)  评论(0编辑  收藏  举报
如果我们时时忙着展现自己的知识, 将何从忆起成长所需的无知?