Wednesday, January 5, 2011

How to create an ActionButton in ASP.NET/MVC?

In Model of MVC: you create a html helper by static class

public static class Action
{
public static string ActionButton(this HtmlHelper helper, string Url, string Text)
{
return string.Format(@"<input type='button' onclick=""javacript: window.location='{1}';"" value='{0}' />", Text, Url);
}
}

In html source view of ASPX file:
<%=Html.ActionButton(Page.ResolveUrl("~/ControllerName/ActionName"),"buttonText") %>

No comments:

Post a Comment