MVC Html.ActionLink无法渲染.你能发现我做错了什么吗?

Rya*_*yan 2 asp.net-mvc razor

我在部分视图中的IF语句中有一个Html.ActionLink,它没有按预期为我呈现超链接.我在行上放置了一个断点,并确认IF语句实际上已得到满足,并且其中的代码正在运行.我也是,作为一个额外的措施,尝试用硬字符串替换Substring.任何想法为什么没有链接为我呈现此代码?

<p>
    Resume (Word or PDF only): @if (Model.savedresume.Length > 0) { Html.ActionLink(Model.savedresume.Substring(19), "GetFile", "Home", new { filetype = "R" }, null); }
</p>
Run Code Online (Sandbox Code Playgroud)

Str*_*ior 7

把一个@Html.ActionLink(...)

Razor @用于许多不同的目的,大多数时候它非常直观,但在这种情况下,很容易错过这个问题.

@if (Model.savedresume.Length > 0) // This @ puts Razor from HTML mode 
                                   // into C# statement mode
{ 
    @Html.ActionLink( // This @ tells Razor to output the result to the page,
                      // instead of just returning an `IHtmlString` that doesn't
                      // get captured.
        Model.savedresume.Substring(19), 
        "GetFile", "Home", new { filetype = "R" }, 
        null) // <-- in this mode, you're not doing statements anymore, so you
              //     don't need a semicolon.
}
Run Code Online (Sandbox Code Playgroud)