I have a partial view and int it, there is no trace of any inheritance from any layout. But whenever I want to use it (render) inside the view, the layout is repeated once for the view and once for the partial view. This post suggests creating an empty layout. But I think this is a workaround. In any case, stop loading the layout (layout) for partial views. I donβt understand why, when there is no code to use the layout of the wizard, why download it. This is similar to creating a page in ASP.NET and inheriting it from the main page without the <%@ Master ... directive.
This is my partial view:
@* 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--; }
source share