简体   繁体   English

.NET MVC URL是否忽略路由?

[英].NET MVC URL IgnoreRoute?

In my application, I am having problems getting a stylesheet because it is using the URL, and trying to find a corresponding controller. 在我的应用程序中,由于使用URL而无法获取样式表,并试图找到相应的控制器。 For Example, 例如,

I have the following in one of my views: 我的其中一种看法如下:

<link href="~/Content/css/styles.css" type="text/css"/>

Which when the page loads, throws a 500 error, and tells me that... 该页面加载时会引发500错误,并告诉我...

www.mysite.com/design/Content/css/styles.css could not be found

It is using design as the area, because that is the name of the package it is in. 它使用设计作为区域,因为这是它所在的包的名称。

What do I need to do in order to hit my static css file at the above address, without it trying to find a controller named "Content"? 在不尝试查找名为“ Content”的控制器的情况下,我该怎么做才能在上述地址访问我的静态CSS文件?

It sounds like you want a domain-relative path rather than an application-relative path. 听起来您想要的是域相对路径,而不是应用程序相对路径。

Remove the ~ . 删除~

Shouldn't the html be rendered using: 不应使用以下方式呈现html:

<link rel="stylesheet" type="text/css" href="<%= Url.Content("~/Content/css/styles.css") %>" />

Or: 要么:

<link rel="stylesheet" type="text/css" href="@Url.Content("~/Content/css/styles.css")" />

(If you are using Razor). (如果您使用的是Razor)。

I dont think this is an issue with your MVC routes, but more that you are not resolving the url correctly. 我认为这与您的MVC路由无关,但更多的是您无法正确解析网址。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM