我有一个局部视图和int它,没有从任何布局的任何继承的痕迹。但是,无论何时我想在视图中使用它(渲染它),布局都会重复一次以获取视图,并且一次获取部分视图。 This post建议创建一个空的布局。但我认为这是解决方法。无论如何停止加载部分视图的布局(主布局)。我不明白,为什么当没有代码使用主布局,为什么它应该被加载。这就像在ASP.NET中创建页面一样,并且看到它从主页面继承而没有<%@ Master ...
指令。部分视图继承自主布局
这是我的部分观点:
@* Recursive category rendering *@
@using Backend.Models;
@{
List<Category> categories = new ThoughtResultsEntities().Categories.ToList();
int level = 1;
}
@RenderCategoriesDropDown(categories, level)
@helper RenderCategoriesDropDown(List<Category> categories, int level)
{
List<Category> rootCategories = categories.Where(c => c.ParentId == null).ToList();
<select id='categoriesList' name='categoriesList'>
@foreach (Category rootCategory in rootCategories)
{
<option value='@rootCategory.Id' class='level-1'>@rootCategory.Title</option>
@RenderChildCategories(categories, level, rootCategory.Id);
}
</select>
}
@helper RenderChildCategories(List<Category> categories, int level, int parentCategoryId)
{
string padding = string.Empty;
level++;
List<Category> childCategories = categories.Where(c => c.ParentId == parentCategoryId).ToList();
foreach (Category childCategory in childCategories)
{
<option value='@childCategory.Id' class='[email protected]'>@padding.PadRight(level, '-') @childCategory.Title</option>
@RenderChildCategories(categories, level, childCategory.Id);
}
level--;
}
可以显示您的部分页面的第一行以及您的控制器操作方法,从而覆盖了此行为? –