views:

364

answers:

2

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.

+3  A: 

remove the semicolon

chris166
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.
smercer
A: 

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.

Ray Vernagus