我有一個局部視圖和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--;
}
可以顯示您的部分頁面的第一行以及您的控制器操作方法,從而覆蓋了此行爲? –