Friday, January 21, 2011

HTML.Button in ASP.NET MVC

Starting from ASP.NET MVC Preview 3, HTML.Button ( and other related HTML controls) are no longer supported.

The question is, what is the equivalent for them? I've an app that was built using Preview 2, now I have to make it compatible with the latest CTP releases.

  • Just write <input type="button" ... /> to your html. There's nothing special at all with the html controls.

    Junior Mayhé : look at http://stackoverflow.com/questions/407770/mapping-individual-buttons-on-asp-net-mvc-view-to-controller-actions
  • <asp:Button> is the ASP.NET equivalent to the HTML.Button. It will by default generate an <input type="button">. (This is the System.Web.UI.WebControls.Button class)

    From Thunder3
  • I got it figure out. It goes something like this:

    <form method="post" action="<%= Html.AttributeEncode(Url.Action("CastUpVote")) %>">
    <input type="submit" value="<%=ViewData.Model.UpVotes%> up votes" />
    </form>
    

    Thanks everyone for their help!

  • Several of the extension methods got moved to Microsoft.Web.Mvc, which is the MVC Futures DLL. You might want to look there for things that have gone missing.

0 comments:

Post a Comment