加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net-mvc – 部分视图继承自主布局

发布时间:2020-12-16 04:22:08 所属栏目: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")

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读