【发布时间】:2014-02-02 17:11:43
【问题描述】:
我正在使用ASP.Net MVC 4。我在一个视图上有多个按钮。目前我正在调用相同的操作方法;我正在使用 name 属性区分单击的按钮。
@using (Html.BeginForm("Submit", "SearchDisplay", new { id = Model == null ? Guid.NewGuid().ToString() : Model.SavedSearch }, FormMethod.Post))
{
<div class="leftSideDiv">
<input type="submit" id="btnExport" class="exporttoexcelButton"
name="Command" value="Export to Excel" />
</div>
<div class="pageWrapperForSearchSubmit">
<input type="submit" class="submitButton"
value="Submit" id="btnSubmitChange" />
</div>
}
//动作
[HttpPost]
public ActionResult Submit(SearchCostPage searchModel, string Command)
{
SessionHelper.ProjectCase = searchModel.ProjectCaseNumber;
if (string.Equals(Command, Constants.SearchPage.ExportToExcel))
{
}
}
问题
- 有没有办法在不同的按钮点击时指向不同的 POST 操作方法(无需自定义路由)?
- 如果没有自定义路由就没有办法,那么自定义路由怎么办?
参考资料:
【问题讨论】:
-
JS 将允许您预处理您的提交请求,这并不意味着您仍然不能有完整的回发。
-
我已经发布了答案。
-
我已编辑您的问题标题以使其更准确,并添加了一个简单有效的答案(在我的一些项目中进行生产)。
-
为什么不使用多个提交按钮路由 stackoverflow.com/questions/442704/…
-
This Tutorial 可能会有所帮助。