gpt4 book ai didi

asp.net-mvc - 部分 View 继承自主布局

转载 作者:行者123 更新时间:2023-12-04 09:04:30 24 4
gpt4 key购买 nike

我有一个局部 View 和 int 它,没有任何布局的任何继承痕迹。但是每当我想在 View 中使用它(渲染它)时,布局都会为 View 重复一次,为局部 View 重复一次。 This post建议创建一个空布局。但我认为这是解决方法。无论如何停止加载部分 View 的布局(主布局)。我不明白,为什么当没有使用主布局的代码时,为什么要加载它。这就像在 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--;
}

最佳答案

通过ajax调用呈现部分页面时,我能够重现这个问题。这

return View("partialpage")   

总是伴随着布局。我通过显式调用覆盖了这种行为
return PartialView("partialpage")  

关于asp.net-mvc - 部分 View 继承自主布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6546517/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com