ActionLink CS1026 :)预期

Joh*_*hn_ 11 c# asp.net asp.net-mvc

每当我尝试使用ActionLink时,我都会收到上述错误?我刚开始玩MVC并且不太了解代码的问题(下面):

<%= Html.ActionLink("Lists", "Index", "Lists"); %>
Run Code Online (Sandbox Code Playgroud)

这似乎只是一个解析问题,但只有在我运行页面时才会发生.应用程序构建完美,所以我真的不明白,因为错误是编译错误?如果我采取第25行,它将发生在下一行而不是......

 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 
Run Code Online (Sandbox Code Playgroud)

Mik*_*ott 25

从ActionLink行中删除分号.

注意:使用时<%= ... %>没有分号,代码应该返回一些东西,通常是一个字符串.在使用时<% ...; %>,即在百分比之后没有等于,代码应返回void,并且在结束百分比之前需要一个分号.

例如,当使用Html方法时,VS intellisense将告诉您它是否返回void.如果是这样,请不要使用等号并以分号结束.

  • 评估<%= ...%>,执行<%...%>是我喜欢记住它的方式. (4认同)

max*_*xnk 5

使用它而不用尾随分号:

<%= Html.ActionLink("Lists", "Index", "Lists") %>
Run Code Online (Sandbox Code Playgroud)