Sand
Sand

Reputation: 51

How do i include mvc3 razor variable in javascript?

My Code:

<script type="text/javascript">
    var root = @Url.Content("~/Content/");
</script>

This has no effect.

<script type="text/javascript">
    var root = '@Url.Content("~/Content/WebApp/img/")';
</script>

Solution.

Upvotes: 1

Views: 1917

Answers (1)

Codo
Codo

Reputation: 79033

The first code sample is missing a pair of single or double quotes. The second one is ok. It works for me.

Or what do you mean by "This has no effect."? Have you looked at the generated HTML code? What do you get?

Upvotes: 2

Related Questions