asp.net-mvc – 部分视图继承自主布局
发布时间:2020-05-24 12:29:33 所属栏目:asp.Net 来源:互联网
导读:我有一个局部视图和int it,没有任何布局的任何继承的痕迹.但每当我想在视图中使用它(渲染它)时,布局会对视图重复一次,对局部视图重复一次. This post建议创建一个空布局.但我认为这是解决方法.无论如何都要停止为部分视图加载布局(主布局).我不明白,为什么当
|
我有一个局部视图和int it,没有任何布局的任何继承的痕迹.但每当我想在视图中使用它(渲染它)时,布局会对视图重复一次,对局部视图重复一次. 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,childCategory.Id);
}
level--;
}
解决方法通过ajax调用渲染部分页面时,我能够重现此问题.该return View("partialpage")
总是伴随着布局.我通过显式调用覆盖了这种行为 return PartialView("partialpage") (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net – GridView中的多个DataKeyNames
- asp.net – URL长度的最佳限制是什么? 100,200
- IIS 7应用程序池标识权限
- 如何保护经典ASP ASPSESSIONID cookie?
- asp.net-mvc – 我何时以及为什么要考虑asp.net MVC?
- asp.net-mvc-3 – 如何在本地测试时禁用elmah发送电子邮件?
- 如何设置特定于ASP.NET请求的log4net上下文属性?
- asp.net-mvc – asp fontawesome 404(未找到)
- asp.net-mvc – 双引号之间的Razor代码
- asp.net-mvc – 在MVC Razor中,如何在子布局下面定义一个Re
推荐文章
站长推荐
热点阅读
