Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc Razor视图和HTML文本_Asp.net Mvc_Razor - Fatal编程技术网

Asp.net mvc Razor视图和HTML文本

Asp.net mvc Razor视图和HTML文本,asp.net-mvc,razor,Asp.net Mvc,Razor,我正试图抓住剃须刀,但遇到了一个基本的障碍。我根据用户的身份验证状态生成一个小菜单。但是,我做错了 <div> <a href="/">Home</a>&nbsp;&nbsp; <a href="/">List</a> @if (Request.IsAuthenticated) { &nbsp; &nbsp; <a h

我正试图抓住剃须刀,但遇到了一个基本的障碍。我根据用户的身份验证状态生成一个小菜单。但是,我做错了

<div>
    <a href="/">Home</a>&nbsp;&nbsp; 
    <a href="/">List</a>
    @if (Request.IsAuthenticated)
    {
        &nbsp;
        &nbsp;
        <a href="/">Upload</a>
        &nbsp;
        &nbsp;
        <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>&nbsp;&nbsp;  
                        <a href="/">List</a> 
                        @if (Request.IsAuthenticated) 
                        { @Html.Raw("
                            &nbsp; 
                            &nbsp; 
                            <a href="/">Upload</a> 
                            &nbsp; 
                            &nbsp; 
                            <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>&nbsp;&nbsp;  
                        <a href="/">List</a> 
                        @if (Request.IsAuthenticated) 
                        { @Html.Raw("
                            &nbsp; 
                            &nbsp; 
                            <a href="/">Upload</a> 
                            &nbsp; 
                            &nbsp; 
                            <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>&nbsp;&nbsp; 
<a href="/">List</a>
@if (Request.IsAuthenticated)
{
    <text>
    &nbsp;
    &nbsp;
    </text>
    <a href="/">Upload</a>
    <text>
    &nbsp;
    &nbsp;
    </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>&nbsp;&nbsp; 
<a href="/">List</a>
@if (Request.IsAuthenticated)
{
    <text>
    &nbsp;
    &nbsp;
    </text>
    <a href="/">Upload</a>
    <text>
    &nbsp;
    &nbsp;
    </text>
    <a href="/logout" onclick="return confirm('Are you sure you want to delete this image?');">Logout</a>
}
  </div>

@如果(请求已验证)
{
}