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

Tags: css,,,

Problem :

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");

Solution :

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.

    CSS Howto..

    simple css issue - how to change anchor inside li if li:hover

    CSS: How to set position absolute of a span inside a relative-position-div which contains [closed]

    How can I redirect a request file to real folder with htaccess?

    how to add class to razor form and give padding?

    How-to set background-position-x?

    how to position nested list items?

    How to Set Two Transition Durations for Multiple CSS Transforms

    How to Insert Images inside DIV in this case

    How to add html classes to a Django template 'for-loop' dynamically?

    How to remove an element without id

    How to do a dynamic pulsating button in javascript?

    How to remove right border

    How to align element based on the other element that is above

    How to add tabs or spaces to a textline with CSS?

    JQuery with IE reading inherted css property, how to prevent?

    How to change background image with static css and maintain it?

    How to center video source in circle shape using css, html

    How to keep your current screen position while dynamically showing surrounding elements with jquery / css

    How to change extjs grid single cell background color depending on value changes?

    How to use a JQuery Show/Hide script, to show hidden text

    How to use Bootstrap Glyphicons in Holder.js images

    How to get this hover effect with just CSS

    How to get the current year using css?

    How do I line up CSS elements? Is there a tool I can use?

    How to speed up a slow loading PHP page that is processing several large arrays?

    How does one load a CSS framework in Rails 3.1?

    Asp.Net how to apply a css style to all the control of it's kind

    how to display data in html

    CSS: How to remove the space around? [duplicate]

    How to expand input field to the right in a header bar