Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.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 core 在_Layout.cshtml中加载分离的cshtml文件_Asp.net Core_Razor - Fatal编程技术网

Asp.net core 在_Layout.cshtml中加载分离的cshtml文件

Asp.net core 在_Layout.cshtml中加载分离的cshtml文件,asp.net-core,razor,Asp.net Core,Razor,我正在学习asp.net核心,并开始了一个新的webapp项目 目前,我将我的sidebar.cshtml与\u Layout.cshtml分开,因为它太长,无法阅读。 我想知道如何在\u Layout.cshtml中加载我的侧边栏.cshtml sidebar.cshtml和\u Layout.cshtml在同一个文件夹中-共享 我在\u Layout.cshtml中尝试过类似的方法,但效果并不理想: <script> $(function () { $("

我正在学习asp.net核心,并开始了一个新的webapp项目

目前,我将我的
sidebar.cshtml
\u Layout.cshtml
分开,因为它太长,无法阅读。 我想知道如何在
\u Layout.cshtml
中加载我的
侧边栏.cshtml

sidebar.cshtml
\u Layout.cshtml
在同一个文件夹中-
共享

我在
\u Layout.cshtml
中尝试过类似的方法,但效果并不理想:

<script>
    $(function () {
        $(".sidebar").load("sidebar.cshtml");
    });
</script>
<div class="sidebar">
</div>

$(函数(){
$(“.sidebar”).load(“sidebar.cshtml”);
});

非常感谢你的帮助

首先,您需要将
sidebar.cshtml
作为
局部视图
。然后在
\u Layout.cshtml
中,添加此
局部视图
,如下所示

<div class="sidebar">
  <partial name="sidebar.cshtml" /> @*in case of sidebar.cshtml in Shared folder.*@
</div>

@*如果是共享文件夹中的sidebar.cshtml*@

最后,运行项目并享受。

首先,您需要将
sidebar.cshtml
作为
局部视图
。然后在
\u Layout.cshtml
中,添加此
局部视图
,如下所示

<div class="sidebar">
  <partial name="sidebar.cshtml" /> @*in case of sidebar.cshtml in Shared folder.*@
</div>

@*如果是共享文件夹中的sidebar.cshtml*@
最后,运行项目并享受