1

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 @Style.Render('"~/Content/css") instead of .....css Commented Aug 11, 2014 at 7:41

3 Answers 3

4

Use

@Styles.Render("~/Content/css")

instead of

@Styles.Render("~/Content/registration.css")
Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

0

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.

12 Comments

when i m using @Url.Content("~/Content/registration.css"), it sets double quotes values on the page. i mean it prints ~/Content/registration.css on the page.
<style type="text/css">@Url.Content("~/Content/registration.css")</style> not working again
@Mayank..or write it as.... <link href="@Url.Content("~/Content/registration.css")" rel="stylesheet" type="text/css" />
@Mayank..there will be problem somewhere else...<link href="@Url.Content("~/Content/registration.css")" rel="stylesheet" type="text/css" />...this will work perfectly...just check path of css file..
will i have to include this css file in _Layout.cshtml file or in RegisterUser.cshtml file ??
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.