ASP.NET MVC - ViewUserControl中的CSS类 - 未定义类或CssClass

时间:2021-04-25 03:38:04

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.

我在ViewUserControl中有一个

,我给它的标签是一个class =“tblRaised”属性/值。 Visual Studio保留底层tblRaised并告诉我 - 未定义类或CssClass。

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?

为什么intellisense引擎试图在这里验证我的CSS类名?其他人遇到这个?这是一个错误吗? intellisense如何知道我的css文件在ViewUserControl中的位置?

3 个解决方案

#1


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.

由于样式通常包含在视图或母版页中,因此VS无法在ViewUserControl中找到它们。如果你在ViewUserControl中添加如下内容,你可以解决问题(并获得intellisense)而不包括CSS两次。

<% 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.

这将获得intellisense,因为它可以找到样式表,但if(false)的使用实际上阻止它在运行时被包含。

#2


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.

通常在ASP.NET世界(而不是MVC)中,您可以在母版页或当前页面中指定样式。 VS然后读取所有样式信息,然后尝试帮助intellisense在打字时将样式中的类名输出到aspx页面。对于MVC,它试图做同样的事情,但它可能只是找不到你的文件,并发出警告。

Just ignore it for now, I'm sure they are going to try and support that with the 1.0 release.

暂时忽略它,我相信它们会尝试用1.0版本来支持它。

#3


It's a known bug. Visual Studio IntelliSense is being too helpful. :)

这是一个已知的错误。 Visual Studio IntelliSense太有用了。 :)

Use this workaround in your user control markup files, it will make VS IntelliSense happy:

在用户控件标记文件中使用此变通方法,它将使VS IntelliSense满意:

<% if (false) { %><link href="../../Content/Css/MyCssDefinitions.css" rel="Stylesheet" type="text/css" /><% } %>

#1


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.

由于样式通常包含在视图或母版页中,因此VS无法在ViewUserControl中找到它们。如果你在ViewUserControl中添加如下内容,你可以解决问题(并获得intellisense)而不包括CSS两次。

<% 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.

这将获得intellisense,因为它可以找到样式表,但if(false)的使用实际上阻止它在运行时被包含。

#2


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.

通常在ASP.NET世界(而不是MVC)中,您可以在母版页或当前页面中指定样式。 VS然后读取所有样式信息,然后尝试帮助intellisense在打字时将样式中的类名输出到aspx页面。对于MVC,它试图做同样的事情,但它可能只是找不到你的文件,并发出警告。

Just ignore it for now, I'm sure they are going to try and support that with the 1.0 release.

暂时忽略它,我相信它们会尝试用1.0版本来支持它。

#3


It's a known bug. Visual Studio IntelliSense is being too helpful. :)

这是一个已知的错误。 Visual Studio IntelliSense太有用了。 :)

Use this workaround in your user control markup files, it will make VS IntelliSense happy:

在用户控件标记文件中使用此变通方法,它将使VS IntelliSense满意:

<% if (false) { %><link href="../../Content/Css/MyCssDefinitions.css" rel="Stylesheet" type="text/css" /><% } %>