Created
February 14, 2011 18:03
-
-
Save mxmissile/826264 to your computer and use it in GitHub Desktop.
ActionButton
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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