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;
     }
}

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-19
  • 2022-02-08
  • 2021-10-10
  • 2021-07-15
猜你喜欢
  • 2022-02-21
  • 2022-12-23
  • 2022-12-23
  • 2021-11-12
  • 2021-08-22
  • 2022-12-23
相关资源
相似解决方案