views:

856

answers:

2

I get the above error whenever I try and use ActionLink ? I've only just started playing around with MVC and don't really understand what it's problem is with the code (below):

<%= Html.ActionLink("Lists", "Index", "Lists"); %>

This just seems to be a parsing issue but it only happens when I run the page. The application builds perfectly fine, so I really don't get it because the error is a compilation error? If I take line 25 out it will happen on the next line instead...

 Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS1026: ) expected

Source Error:

Line 23:   </div>
Line 24:   
Line 25:   <%= Html.ActionLink("Lists", "Index", "Lists"); %>
Line 26:   <a href="<%= Url.Action("/", "Lists"); %>">Click here to view your lists</a>
Line 27:   


Source File: d:\Coding\Playground\HowDidYouKnowMVCSoln\HowDidYouKnowMVC\Views\Home\Index.aspx    Line: 25
+3  A: 

Use it without trailing semicolon:

<%= Html.ActionLink("Lists", "Index", "Lists") %>
maxnk
+9  A: 

Remove the semi-colon from the ActionLink line.

Note: when using <%= ... %> there's no semi-colon and the code should return something, usually a string. When using <% ...; %>, i.e. no equals after the percent, the code should return void and you need a semi-colon before the closing percent.

When using Html methods, for example, VS intellisense will tell you whether it returns void. If so, don't use an equals and terminate with a semi-colon.

Mike Scott
<%= ... %> is evaluated, <% ... %> is executed is how I like to remember it.
Will