MVC CSS on view page (not _layout) not working

北城余情 提交于 2021-02-18 18:54:56

问题


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.enter image description here


回答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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!