简体   繁体   English

Css在asp.net mvc3 Razor Views中无法正常工作

[英]Css is not working properly in asp.net mvc3 Razor Views

I have a application on asp.net mvc3 and working in a razor view. 我在asp.net mvc3上有一个应用程序,并在剃须刀视图中工作。 On my layout page I attach a css file and put some css in that file, but when I access /Account/LogOn view the css is not working. 在我的布局页面上,我附加了一个css文件并在该文件中放入了一些css,但是当我访问/Account/LogOn视图时,css无法正常工作。
It only works if I attach the css on Logon view. 它仅在我在Logon视图上附加css时才有效。 Anyone know why my css attached on the layout page is not working on /Account/LogOn ? 任何人都知道为什么布局页面上附加的CSS不能用于/Account/LogOn

I also tried by including following code: 我还试过包括以下代码:

@{
Layout = "~/Views/Shared/_Layout.cshtml";
ViewBag.Title = "xyz.com – Login";
 }

It is still not working. 它仍然无法正常工作。 Thanks in advance 提前致谢

像这样使用url helper引用你的css

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

In your _layout.cshtml , ensure that you use a path referencing the root (~) of your application. _layout.cshtml ,确保使用引用应用程序根目录(〜)的路径。 Use @Url.Content() to escape the path: 使用@Url.Content()来转义路径:

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

Create the stylesheet under the folder Contents by the name say abc.css 在文件夹Contents下创建样式表,名称为abc.css

Now include the stylesheet in the LayoutPage so that it is included automatically in all the pages derived from the content page. 现在在LayoutPage中包含样式表,以便它自动包含在从内容页面派生的所有页面中。

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

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

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