【发布时间】:2011-07-01 10:05:12
【问题描述】:
我有一个局部视图和 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='level-@level'>@padding.PadRight(level, '-') @childCategory.Title</option>
@RenderChildCategories(categories, level, childCategory.Id);
}
level--;
}
【问题讨论】:
-
你能显示你的部分页面的第一行和你的控制器操作方法吗?
标签: asp.net-mvc asp.net-mvc-3 layout master-pages partial-views