RSSArchive for May, 2012



Add attributes to Html.BeginForm in MVC

Posted by 2 Comments

If you want to add attributes to a form generated from Html.BeginForm() in MVC, you can do so by passing them as htmlAttributes parameters. Note that this means you will need to pass a few other parameters as well:

Html.BeginForm( action, controller, FormMethod, htmlAttributes )

So if we want to give our form an attribute Id=”formname”, we can use:

Html.BeginForm( "Login", "Home", FormMethod.Post, new { id=”formname” })

Continue Reading



Using jQuery dialog in an MVC4 Mobile App

Posted by 4 Comments

According the jQuery Mobile Documentation for dialogs, you would open the dialog by adding


to the link. However, in an MVC4 Mobile app you need to add data_rel (note the ‘_’ not ‘-‘) to your actionlink like so:

@Html.ActionLink("Log in", "Login", "Account", routeValues: null, 
  htmlAttributes: new { data_icon = "gear", data_rel = "dialog" })

Continue Reading