Dynamically assign class name to HTML in asp.net razor syntax

August 1st, 2012 by admin Leave a reply »

IF you are struggling with getting your html formatted correctly in asp.net like I am here is a little tip I found to set your html based on css classes you have in your css file.

@Html.CheckBoxFor(x => data.Selected, new { @class = "checkbox" })

I tried just wrapping the asp syntax in a div and that didn’t give me the results that I was looking for and besides, this syntax is a lot cleaner. There are other HTML options in the razor syntax but I couldn’t locate a good list anywhere, if you know of one, don’t hesitate to leave me a message and I will get this post updated with that information, thanks.

Advertisement

Leave a Reply