问题
I have a problem with MVC4 CSS. i m including a CSS file named registration.css in an another view page named "registerUser.cshtml". This page is like a content page in mvc4 razor. but problem is that CSS is not working.
How can i resolve this. I have also included in BundleConfig.cs as
bundles.Add(new StyleBundle("~/Content/css").Include("~/Content/registration.css"));
But it is also not working. Help me.
回答1:
Use
@Styles.Render("~/Content/css")
instead of
@Styles.Render("~/Content/registration.css")
回答2:
I got my answer. Actually another css file from _Layout.cshtml overwrites the view page css file. when i removed main.css from Viewpage.cshtml, it works fine. Well, Thanks to all, thanks @Exception - u gave me important knowledge.
回答3:
If you want a single css file on a page then use this :
<link href="@Url.Content("~/Content/registration.css")" rel="stylesheet" type="text/css" />
OR
If you want many css files on Layout Page or at any View Page then make it's bundle and include it in this way:
@Styles.Render("~/Content/css")
You are using @Styles.Render("~/Content/registration.css")
which is wrong..try above solution.
来源:https://stackoverflow.com/questions/25238060/mvc-css-on-view-page-not-layout-not-working