【问题标题】:ActionLink CS1026: ) expectedActionLink CS1026:) 预期
【发布时间】:2008-12-13 17:39:40
【问题描述】:

每当我尝试使用 ActionLink 时都会出现上述错误?我才刚刚开始使用 MVC,并不太明白代码有什么问题(如下):

<%= 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 

【问题讨论】:

    标签: c# asp.net asp.net-mvc


    【解决方案1】:

    从 ActionLink 行中删除分号。

    注意:当使用&lt;%= ... %&gt; 时,没有分号,代码应该返回一些东西,通常是一个字符串。使用&lt;% ...; %&gt; 时,即百分号后不等于,代码应返回 void,您需要在结束百分号前加分号。

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

    【讨论】:

    • 被评估, 被执行是我喜欢记住的方式。
    【解决方案2】:

    使用不带分号:

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

    【讨论】:

      【解决方案3】:

      就我而言,我真的错过了 ActionLink 末尾的 )。

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-12-28
        • 1970-01-01
        • 1970-01-01
        • 2011-05-05
        • 2011-05-25
        • 2011-12-12
        相关资源
        最近更新 更多