2

I have the following ASP.NET MVC page written in razor:

@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <title>SelectorTests</title>
    <link href="@{ Url.Content("~/Content/themes/base/jquery-ui.css"); }" rel="stylesheet" type="text/css" />
    <script src="@{ Url.Content("~/Scripts/jquery-1.4.4.min.js"); }" type="text/javascript"></script>
    <script src="@{ Url.Content("~/Scripts/jquery-ui.min.js"); }" type="text/javascript"></script>

    <script type="text/javascript">
        $(function () {
            $('h1').css('background-color', 'purple');
        });        
    </script>
</head>
<body>
    <div>
        <h1>My Header</h1>
        foobar
    </div>
</body>
</html>

URL.Content isn't working properly. When I do a View Source in FF, the relevant lines come back as

<link href="" rel="stylesheet" type="text/css" />
<script src="" type="text/javascript"></script>
<script src="" type="text/javascript"></script>

Please assist.

2 Answers 2

8

You're using curly braces when there is no need to.

<link href="@{ Url.Content("~/Content/themes/base/jquery-ui.css"); }" rel="stylesheet" type="text/css" />

Should be:

<link href="@Url.Content("~/Content/themes/base/jquery-ui.css")" rel="stylesheet" type="text/css" />

You need only wrap code in curly braces when there is no return value. For example if you were declaring a variable. You would not need curly braces to then output the contents of the variable.

@{
    var foo = "bar";
}
<p>@foo</p>

Rich

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

Comments

1

Try the following

<link href="@Url.Content("~/Content/themes/base/jquery-ui.css")" rel="stylesheet" type="text/css" />
<script src="@Url.Content("~/Scripts/jquery-1.4.4.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery-ui.min.js")" type="text/javascript"></script>

Comments

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.