Asp.net mvc Razor视图和HTML文本
我正试图抓住剃须刀,但遇到了一个基本的障碍。我根据用户的身份验证状态生成一个小菜单。但是,我做错了Asp.net mvc Razor视图和HTML文本,asp.net-mvc,razor,Asp.net Mvc,Razor,我正试图抓住剃须刀,但遇到了一个基本的障碍。我根据用户的身份验证状态生成一个小菜单。但是,我做错了 <div> <a href="/">Home</a> <a href="/">List</a> @if (Request.IsAuthenticated) { <a h
<div>
<a href="/">Home</a>
<a href="/">List</a>
@if (Request.IsAuthenticated)
{
<a href="/">Upload</a>
<a href="/logout" onclick="return confirm('Are you sure you want to delete this image?');">Logout</a>
}
</div>
我的模型是:
{
public class IndexModel
{
public string RandomImageUrl { get; set; }
}
}
如果您想显示HTML中的内容,可以使用例如@HTML.Raw()方法。所以你的代码可能是
<div>
<a href="/">Home</a>
<a href="/">List</a>
@if (Request.IsAuthenticated)
{ @Html.Raw("
<a href="/">Upload</a>
<a href="/logout" onclick="return confirm('Are you sure you want to delete this image?');">Logout</a> ")
}
</div>
@如果(请求已验证)
{@Html.Raw(“
")
}
如果您想显示来自HTML的内容,可以使用例如@HTML.Raw()方法。所以你的代码可能是
<div>
<a href="/">Home</a>
<a href="/">List</a>
@if (Request.IsAuthenticated)
{ @Html.Raw("
<a href="/">Upload</a>
<a href="/logout" onclick="return confirm('Are you sure you want to delete this image?');">Logout</a> ")
}
</div>
@如果(请求已验证)
{@Html.Raw(“
")
}
Razor无法检测到您正在进入HTML模式。使用特殊的
Razor标记表示您处于HTML模式。Razor无法检测到您正在进入HTML模式。使用特殊的
Razor标记表示您处于HTML模式。nbsp表示不间断空格。它在HTML中用于插入中间的空格。因为你处于剃须刀代码的中间,编译器不知道你什么时候使用HTML代码,同时没有指令。因为它会给出一个编译错误。这更像是c中的预处理器指令。(如果你知道,包括在内)。在这里,您只需使用。正确的代码如下所示
<div>
<a href="/">Home</a>
<a href="/">List</a>
@if (Request.IsAuthenticated)
{
<text>
</text>
<a href="/">Upload</a>
<text>
</text>
<a href="/logout" onclick="return confirm('Are you sure you want to delete this image?');">Logout</a>
}
</div>
@如果(请求已验证)
{
}
nbsp表示不间断空间。它在HTML中用于插入中间的空格。因为你处于剃须刀代码的中间,编译器不知道你什么时候使用HTML代码,同时没有指令。因为它会给出一个编译错误。这更像是c中的预处理器指令。(如果你知道,包括在内)。在这里,您只需使用。正确的代码如下所示
<div>
<a href="/">Home</a>
<a href="/">List</a>
@if (Request.IsAuthenticated)
{
<text>
</text>
<a href="/">Upload</a>
<text>
</text>
<a href="/logout" onclick="return confirm('Are you sure you want to delete this image?');">Logout</a>
}
</div>
@如果(请求已验证)
{
}