BuddyJoe
BuddyJoe

Reputation: 71111

ASP.NET MVC - CSS Class in a ViewUserControl - The class or CssClass is not defined

I have a <table/> in a ViewUserControl that I have given the tag a class="tblRaised" attribute/value. Visual Studio keeps underlying tblRaised and telling me - The class or CssClass is not defined.

Why is the intellisense engine trying to validate my CSS class names here? Anyone else run into this? Is this a bug? How would intellisense even know where my css file was in a ViewUserControl?

Upvotes: 2

Views: 1286

Answers (3)

tvanfosson
tvanfosson

Reputation: 532505

Because the styles are usually included in your view or master page, VS can't find them in your ViewUserControl. If you add something like the following to your ViewUserControl you can get around the issue (and get intellisense) without including the CSS twice.

<% if (false) { %>
   <link rel="stylesheet" type="text/css" ...
<% } %>

This will get the intellisense since it can find the stylesheet, but the use of if (false) actually prevents it from being included at runtime.

Upvotes: 4

User
User

Reputation: 30965

It's a known bug. Visual Studio IntelliSense is being too helpful. :)

Use this workaround in your user control markup files, it will make VS IntelliSense happy:

<% if (false) { %><link href="../../Content/Css/MyCssDefinitions.css" rel="Stylesheet" type="text/css" /><% } %>

Upvotes: 1

rball
rball

Reputation: 6955

Typically in the ASP.NET world (not MVC) you'd specify your styles in the master page or your current page. VS then reads all the style information and then tries to help with intellisense to output the class names from your styles onto your aspx page while typing. With MVC it is trying to do the same thing, but it's probably just not finding your files, and throwing up a warning.

Just ignore it for now, I'm sure they are going to try and support that with the 1.0 release.

Upvotes: 1

Related Questions