[AttributeUsage(AttributeTargets.Method)] public class MultipleButtonAttribute : ActionNameSelectorAttribute { public string Name { get; set; } public string Argument { get; set; } public override bool IsValidName(ControllerContext controllerContext, string actionName, MethodInfo methodInfo) { var isValidName = false; var keyValue = string.Format("{0}:{1}", Name, Argument); var value = controllerContext.Controller.ValueProvider.GetValue(keyValue); if (value != null) { controllerContext.Controller.ControllerContext.RouteData.Values[Name] = Argument; isValidName = true; } return isValidName; } }
<div class="col-xs-8"> <button type="submit" name="action:SearchDeliveries" class="btn btn-success">Search</button> </div>
<button type="submit" name="action:ExportToCsv" class="btn btn-default">Export</button>
[MultipleButton(Name = "action", Argument = "ExportToCsv")] public ActionResult ExportToCsv(){ // } [MultipleButton(Name = "action", Argument = "SearchDeliveries")] public ActionResult SearchDeliveries(FormCollection fc){ // }
$("#btnDateRangeSearch").click(function() { var frm = $("#searchContainer").parent(); frm.attr("action", "@Url.Action("SearchDeliveries")"); frm.submit(); }); $("#btnExport").click(function () { var frm = $("#searchContainer").parent(); frm.attr("action", "@Url.Action("ExportToCsv")"); frm.submit(); });
ASP.NET MVC 中 如何将同一个form post到不同的action
原文:http://blog.csdn.net/lan_liang/article/details/43678795