我使用两个提交按钮。 (asp.net mvc3 aplicattion)
我发现如何在这里制作: http://blog.maartenballiauw.be/post/2009/11/26/Supporting-multiple-submit-buttons-on-an-ASPNET-MVC-view.aspx
在哪里放这个MultiButtonAttribute类?在控制器?
这可能是最简单的方法。
答案 0 :(得分:1)
您可以在应用程序的任何位置添加它,包括Controller Folder
答案 1 :(得分:1)
**//model**
public class input_element
{
public string Btn { get; set; }
}
**//views**
@using (Html.BeginForm())
{
<button type="submit" name="btn" value="verify">
Verify data</button>
<button type="submit" name="btn" value="save">
Save data</button>
<button type="submit" name="btn" value="redirect">
Redirect</button>
}
**//controller**
public ActionResult About()
{
ViewBag.Message = "Your app description page.";
return View();
}
[HttpPost]
public ActionResult About(input_element model)
{
if (model.Btn == "verify")
{
// the Verify button was clicked
}
else if (model.Btn == "save")
{
// the Save button was clicked
}
else if (model.Btn == "redirect")
{
// the Redirect button was clicked
}
return View();
}