我在部分视图的 IF 语句内有一个 Html.ActionLink,它没有按预期为我呈现超链接。我在该行上放置了一个断点,并确认 IF 语句实际上已满足并且其中的代码正在运行。作为一项额外措施,我还尝试用硬字符串替换子字符串。有什么想法为什么用这段代码没有为我呈现链接吗?
<p>
Resume (Word or PDF only): @if (Model.savedresume.Length > 0) { Html.ActionLink(Model.savedresume.Substring(19), "GetFile", "Home", new { filetype = "R" }, null); }
</p>
Put an @
before Html.ActionLink(...)
剃须刀用途@
出于许多不同的目的,大多数时候它相当直观,但在这种情况下很容易错过问题。
@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.
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)