RSSCategory: .NET



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



Slowing down a loop in .NET

Posted by Leave a Comment

One way to slow down a loop in .NET is to use the System.Threading.Thread.Sleep() method. This will suspend the current thread for a specified amount of time. Note that this is not the same as a timer which fires on the specified interval. The Thread.Sleep method simply pauses that thread for a given amount of time before continuing.

It’s as simple as adding

//Pause current thread for one second before continuing

to the loop you would like to slow down.
Continue Reading