Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to refer to a CSS style using ASP.NET MVC?

In ASP.NET MVC I could define a textBox editor like this and give it a style.

 @Html.TextBoxFor(m => m.Notes[i].Notes, new { style = "width: 500px;" });

How can I move the style to the Site.css file and just refer to it from the code above?

.myStyle {
    width: 500px;
}

I tried this which compiles but doesn't seem to work:

@Html.TextBoxFor(m => m.Notes[i].Notes, "myStyle");
like image 914
Houman Avatar asked Dec 17 '22 02:12

Houman


1 Answers

You want to give it a class attribute for your CSS rule to match:

@Html.TextBoxFor(m => m.Notes[i].Notes, new { @class = "myStyle" });

Note that the @ in @class has no special meaning in ASP.NET MVC. It's simply there to turn class, a keyword in C#, into an identifier, so you can pass it in as a property and it'll compile.

like image 194
BoltClock Avatar answered Dec 24 '22 02:12

BoltClock