【发布时间】:2017-06-19 20:19:47
【问题描述】:
我正在开发小型 MVC 应用程序,并且在我的视图中, 有3个按钮,它们都在调用相同的Action,这里是按钮的定义:
<button type="submit" class="btn btn-success pull-right" id="btnSave" value="tabOne"><i class="fa fa-save"></i> Submit changes </button>
其中三个是这样的,我怎么知道哪个调用了一个方法,因为它们位于三个单独的 TABS 上,并且提交时的每个选项卡(保存更改)都需要重定向到不同的视图,所以这就是原因为什么我需要识别哪个按钮调用了我的 [HttpPost] Edit 操作方法..
这是我正在调用的方法的外观:
[HttpPost]
public ActionResult Edit(ArticleEditViewModel model)
{
if (ModelState.IsValid)
{
//Rest of some code
//Here I need to determine which button called this method so I can redirect user //to a corresponding view, for example
if(button1 invoked me)
{
return RedirectToAction("Edit", "Article");
}
else if(button 2 invoked me)
{
return RedirectToAction("Index", "Article");
}
}
各位,差不多就这些了,我有选项卡控件、3 个提交相同 Action 方法的按钮,我需要弄清楚是哪个按钮调用了某个方法。
谢谢大家 干杯
【问题讨论】:
标签: javascript c# asp.net-mvc razor view