2008-12-13 44 views
11

每当我尝试使用ActionLink时,都会收到上述错误消息?我刚开始玩的MVC周围并没有真正理解与代码(下)那是什么问题:ActionLink CS1026:)预计

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

这只是似乎是一个解析的问题,但是当我运行它只是发生页。应用程序的构建非常好,所以我真的不明白,因为错误是编译错误?如果我走线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 

回答

25

从ActionLink的行删除分号。

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

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

+4

<%= ... %>被评估,<% ... %>被执行是我如何记住它。 – Will 2008-12-13 19:44:46

5

使用它,而尾随分号:

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

在我的情况下,我真的错过了)在ActionLink的结尾处。

<%= Url.Action("SearchPatientSchedules", "PatientSchedules" **)** %>