2008-12-13 46 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" **)** %>