Archive for the ‘Razor’ category

Dynamically assigning css properties within the razor syntax.

February 9th, 2013

You may already know this, but I thought I would share anyways.  When you are writing webpages and you are loading the data dynamically through the razor syntax, it isn’t enough to just wrap your logic inside a <div> that has a class applied to it, you need to assign the css class within in the razor syntax.  The snippet below is an example of how you can assign a css class within the razor syntax:

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

The thing to focus on is the end of the snippet, the “, new { @class = “checkbox” }”  in that example I am setting the class name of the checkbox to a css class I have that styles the checkbox the way I want it to.  I couldn’t really locate an extensive list of these HTMLAttributes, so if you know of anything, please send me a link and I will update this article, thanks!!