11

In my MVC4 project I bundle two css file. When browse render this file then I got two exception.

Uncaught SyntaxError: Unexpected token .
Uncaught SyntaxError: Unexpected token {  

I wrote this code for bundling my CSS files.

public static void RegisterBundles(BundleCollection bundles)
{
    bundles.Add(new StyleBundle("~/Content/css")
    .Include("~/Content/css3.css","~/Content/styles.css"));
}

I call this in my _Layout.chshtml page.

<head>
   @Scripts.Render("~/Content/css")
</head>

and get that exception.

But if I call those CSS files this way then every thing works fine.

<head>
    <link href="~/Content/css3.css" rel="stylesheet" />
    <link href="~/Content/styles.css" rel="stylesheet" />
</head>

Here is a screen shoot of my Error.

enter image description here

1 Answer 1

33

It's because it's rendering a <script> tag. It should be @Styles.Render instead of @Scripts.Render.

Sign up to request clarification or add additional context in comments.

1 Comment

This happened for me when I had a call to @Scripts.Render("~/bundles/custom") in my view that didn't have a corresponding ScriptBundle setup in the BundleConfig.cs 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.