views:

853

answers:

3

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?

Thanks.

+1  A: 

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.

rball
still not fixed in 2.0 on VS2008. I wonder if it works in VS2010?
WildJoe
+1  A: 

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" /><% } %>
User
+4  A: 

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.

tvanfosson