Is there some easy way to handle multiple submit buttons from the same form? For example:
<% Html.BeginForm(\"MyAction\", \"MyController\", FormMethod.Pos
My JQuery approach using an extension method:
public static MvcHtmlString SubmitButtonFor(this HtmlHelper helper, Expression> action, string value) where TController : Controller
{
RouteValueDictionary routingValues = Microsoft.Web.Mvc.Internal.ExpressionHelper.GetRouteValuesFromExpression(action);
var onclick = string.Format("$('form').first().attr('action', '/{0}')", string.Join("/", routingValues.Values.ToArray().Where(x => x != null).Select(x => x.ToString()).ToArray()));
var html = "";
return MvcHtmlString.Create(html);
}
You can use it like this:
@(Html.SubmitButtonFor(c => c.Save(null), "Save"))
And it renders like this: