加载分布视图的方式:
1
2
3
4
5
6
7
8
9
10
|
//1、以视图名使用当前文件夹下的视图(如果没有找到,则搜索 Shared 文件夹)
@Html.Partial( "_test" ) //加载对应文件 /Views/Product/_test.cshtml
//2、依据应用根路径定位视图// 以 "/" 或 "~/" 开头的路径代表应用根路径
@Html.Partial( "~/Views/Product/_test.cshtml" )
@Html.Partial( "/Views/Product/_test2.cshtml" )
//3、加载其他目录的 视图文件
//注意:需要复制views中的web.config 到template目录,否则会提示 "/template/A.cshtml”处的视图必须派生自 WebViewPage 或 WebViewPage<TModel>"
@Html.Partial( "/template/A.cshtml" )
|
web.config 文件(已去掉多余的节点配置)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
<?xml version= "1.0" ?>
<configuration>
<configSections>
<sectionGroup name= "system.web.webPages.razor" type= "System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" >
<section name= "host" type= "System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission= "false" />
<section name= "pages" type= "System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission= "false" />
</sectionGroup>
</configSections>
<system.web.webPages.razor>
<host factoryType= "System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<pages pageBaseType= "System.Web.Mvc.WebViewPage" >
<namespaces>
<add namespace = "System.Web.Mvc" />
<add namespace = "System.Web.Mvc.Ajax" />
<add namespace = "System.Web.Mvc.Html" />
<add namespace = "System.Web.Optimization" />
<add namespace = "System.Web.Routing" />
</namespaces>
</pages>
</system.web.webPages.razor>
</configuration>
|