Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET MVC: How to fix Visual Studio's lack of awareness of CSS classes in partial views?

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?

like image 388
MegaMatt Avatar asked Mar 04 '10 16:03

MegaMatt


1 Answers

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"/> <%}%>
like image 122
bdukes Avatar answered Nov 15 '22 03:11

bdukes