Tutorial :Avoid “The class or CssClass value is not defined” Warnings in ASP.NET MVC ASCX Partial Views (UserControls)



Question:

I wondered how I can stop those annoying compiler warnings "The class or CssClass value is not defined" coming from my ASP.NET MVC partial views/ASCX user controls. The CSS is correctly defined, but the reference to the CSS file is obviously on the master page only. My partial views contain lots of CSS class references on div's etc. and so I get massive amounts of warnings which I shouldn't see.

How can I solve this?

Thank you !


Solution:1

Include this in your partial view:

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

This will make intellisense happy, and excludes the stylesheet when the page is rendered, so that it is not included twice.


Solution:2

One way is to turn HTML Syntax Checking off (Tools->Options->Text editor->HTML->Show Errors->In CSS).

I use the Firefox Tidy plug in, which gives better advice, IMHO.


Solution:3

This is not a flaw in ASP.Net MVC, and I don't think it's going to be it's going to be fixed in the next version. This is a 'limitation' (notice how i avoid the word flaw) in asp.net (not just mvc) that prevents it from accessing header information that's included in the master page. So you don't have access to javascript/css in the content pages/usercontrols.

The code provided by Robert Harvey is a hack solution that we've been using to overcome this.

It works by using the enclosing the include file in an if block that's always false. So the compiler sees the css file but the runtime doesn't.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »