How to access CSS style using ASP.NET MVC?

In ASP.NET MVC, I could define such a textBox editor and give it a style.

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

How to move a style to a Site.css file and just reference it from the code above?

 .myStyle { width: 500px; } 

I tried this which compiles but does not seem to work:

 @Html.TextBoxFor(m => m.Notes[i].Notes, "myStyle"); 
+4
source share
2 answers

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

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

Note that @ in @class does not really matter in ASP.NET MVC. It just needs to turn class , a keyword in C #, into an identifier so that you can pass it as a property and compile it.

+11
source

One word of explanation. Usually, if you want to add attributes, for example. readonly, you would type:

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

Note that there is no @ before readonly. You must put @ in front of the class attribute because it is a keyword in C #. If you do this in VB.NET, you do not need to run because you are defining properties with the host . :

 @Html.TextBoxFor(Function(m) m.Notes[i].Notes, New With { .class = "myStyle" }); 
+1
source

Source: https://habr.com/ru/post/1403590/


All Articles