Skip to content

Instantly share code, notes, and snippets.

@mxmissile
Created February 14, 2011 18:03
Show Gist options
  • Save mxmissile/826264 to your computer and use it in GitHub Desktop.
Save mxmissile/826264 to your computer and use it in GitHub Desktop.
ActionButton
public static MvcHtmlString ActionButton<T>(this HtmlHelper helper, Expression<Action<T>> action, string text) where T : Controller
{
return ActionButton(helper, action, text, null);
}
public static MvcHtmlString ActionButton<T>(this HtmlHelper helper, Expression<Action<T>> action, string text, object htmlAttributes) where T : Controller
{
var routing = ExpressionHelper.GetRouteValuesFromExpression(action);
var vpd = helper.RouteCollection.GetVirtualPath(helper.ViewContext.RequestContext, routing);
if(vpd == null)
return null;
return
MvcHtmlString.Create(
string.Format(
"<input type=\"button\" onclick=\"javacript: window.location='{1}';\" value=\"{0}\" />", text,
vpd.VirtualPath));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment