Asp.net mvc MVC Html.ActionLink未呈现。你能认出我所说的吗;我做错了?
我在部分视图中的IF语句中有一个Html.ActionLink,它没有按预期为我呈现超链接。我在该行上放置了一个断点,并确认IF语句事实上得到了满足,并且其中的代码正在运行。作为额外的措施,我还尝试用硬字符串替换子字符串。你知道为什么没有链接用这段代码呈现给我吗Asp.net mvc MVC Html.ActionLink未呈现。你能认出我所说的吗;我做错了?,asp.net-mvc,razor,Asp.net Mvc,Razor,我在部分视图中的IF语句中有一个Html.ActionLink,它没有按预期为我呈现超链接。我在该行上放置了一个断点,并确认IF语句事实上得到了满足,并且其中的代码正在运行。作为额外的措施,我还尝试用硬字符串替换子字符串。你知道为什么没有链接用这段代码呈现给我吗 <p> Resume (Word or PDF only): @if (Model.savedresume.Length > 0) { Html.ActionLink(Model.savedresume.Sub
<p>
Resume (Word or PDF only): @if (Model.savedresume.Length > 0) { Html.ActionLink(Model.savedresume.Substring(19), "GetFile", "Home", new { filetype = "R" }, null); }
</p>
简历(仅限Word或PDF):@if(Model.savedresume.Length>0){Html.ActionLink(Model.savedresume.Substring(19),“GetFile”,“Home”,new{filetype=“R”},null);}
在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.
}
@if(Model.savedresume.Length>0)//此@将Razor从HTML模式中删除
//进入C#语句模式
{
@ActionLink(//This@告诉Razor将结果输出到页面,
//而不是仅仅返回一个不正确的'IHtmlString'
//被俘。
模型savedresume子字符串(19),
“GetFile”,“Home”,新的{filetype=“R”},
null)//非常感谢您解决了我的问题并给出了精彩的解释。我没有意识到在C#语句模式中有一次需要@来将结果输出到页面。不过这完全有道理。