3

For some reason, I am getting a runtime exception when I try to use Page.ResolveURL or Url.Content within the default masterpage (Site.Master) in my newly created asp.net mvc application. This is very odd, because I have been using the ResolveURL helper function in .NET for years without issue. Here is my code snippet:

<link href="<%= Url.Content("~/css/style.css"); %>" rel="stylesheet" type="text/css" />

And here is the runtime error that occurs on the very same line:

Compiler Error Message: CS1026: ) expected

If I change the href to a static URL, everything is fine. Also, this is a brand new ASP.NET mvc project....this was the first line of code that I changed.

2 Answers 2

6

remove the semicolon

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

1 Comment

Thanks! I had a feeling it was something simple. I've never used scriplets (<% %>) until now, as I've always kept such things in code behinds.
1

Remove the semi-colon from the end. Some MVC helper methods return strings in which case they should appear between <%= %> tags which is appropriate in this case. When using helper methods that return something, you leave the semi-colon off of the end.

Other helper methods return nothing (e.g., Html.RenderPartial) in which cases you use <% %> tags and here you end your code expression with a semi-colon.

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.