避免在ASP中出现“未定义类或CssClass值”警告。NET MVC ASCX部分视图(用户控件)

时间:2021-11-12 06:30:49

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.

我想知道如何阻止那些恼人的编译器警告:“类或CssClass值没有定义”来自我的ASP。NET MVC部分视图/ASCX用户控件。CSS是正确定义的,但是对CSS文件的引用显然只在主页上。我的部分视图包含很多CSS类的引用,比如div等等,所以我得到了大量的警告,我不应该看到。

How can I solve this?

我怎么解决这个问题呢?

Thank you !

谢谢你!

3 个解决方案

#1


10  

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.

这将使intellisense满意,并且在页面被呈现时排除样式表,这样它就不会被包含两次。

#2


6  

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

一种方法是关闭HTML语法检查(工具->选项->文本编辑器->HTML->显示错误->在CSS中)。

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

我使用了Firefox的Tidy插件,它提供了更好的建议,IMHO。

#3


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.

这不是ASP的缺陷。Net MVC,我不认为下一个版本会修复。这是一个“限制”(注意我如何避免“缺陷”)在asp.net(不只是mvc)中,阻止它访问包含在母版页中的头信息。所以在内容页面/用户控件中不能访问javascript/css。

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

Robert Harvey提供的代码是一个破解解决方案,我们一直在使用它来解决这个问题。

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.

它的工作方式是在if块中使用包含的文件,该文件总是为false。编译器看到css文件,但是运行时没有。

#1


10  

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.

这将使intellisense满意,并且在页面被呈现时排除样式表,这样它就不会被包含两次。

#2


6  

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

一种方法是关闭HTML语法检查(工具->选项->文本编辑器->HTML->显示错误->在CSS中)。

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

我使用了Firefox的Tidy插件,它提供了更好的建议,IMHO。

#3


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.

这不是ASP的缺陷。Net MVC,我不认为下一个版本会修复。这是一个“限制”(注意我如何避免“缺陷”)在asp.net(不只是mvc)中,阻止它访问包含在母版页中的头信息。所以在内容页面/用户控件中不能访问javascript/css。

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

Robert Harvey提供的代码是一个破解解决方案,我们一直在使用它来解决这个问题。

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.

它的工作方式是在if块中使用包含的文件,该文件总是为false。编译器看到css文件,但是运行时没有。