RSSCategory: MVC



Escaping Razor View @ Symbol in MVC project

Posted by 1 Comment

To escape the Razor View’s @ symbol in an MVC project you can either use double @ signs:


Or you can use Html.Raw to display the symbol:




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