views:

161

answers:

1

Hi all,

This has been sort of an annoyance for me for a while. I make pretty heavy use of partial views in MVC, and am using Visual Studio 2008 to develop. The problem is that when I give html elements a class in a partial view (<div class="someClass">), it will underline them in green like it doesn't know what they are.

I realize this is because I'm in a partial view, and haven't put link tags anywhere in that file for it to know where the CSS is (the link tags are in the main view that renders the partial view). The CSS still works fine on my site because the browser will render all views as one long html page anyway, but it's really annoying to look through my partial views and see all of my classes underlined in green.

Is there a way that I can still tell Visual Studio that those classes exist somewhere, from the partial view? I figured there has to be a way to let it know, but am not sure what it is. Maybe a way to import the stylesheets from the parent view?

Thanks for your help.

+7  A: 

One way that should work is to include a stylesheet link in the partial that isn't rendered to the page, like so:

<%if (false) {%> <link rel="Stylesheet" href="styles.css"/> <%}%>
bdukes
I suppose this could work, but I was looking for (hopefully) a single statement that would just let VS know that the stylesheet links are in file *x* (or something like that)
Mega Matt
I've researched this exact same problem...this is the simplest solution available.
Neil T.
This is the best solution. Another solution is to write your own ControlBuilder for the Partial View (or a known tag inside which you would place all <link> directives), and get it to intercept all css references so that in design view it could render the correct css tag for the designer. To be honest, though, it's a world of pain and I'd just go with this solution.
Andras Zoltan