Tôi có một phần xem và int nó, không có dấu vết của bất kỳ thừa kế từ bất kỳ bố trí. Nhưng bất cứ khi nào tôi muốn sử dụng nó (hiển thị nó) bên trong một khung nhìn, bố cục được lặp lại một lần cho khung nhìn và một lần cho khung nhìn một phần. This post đề xuất tạo bố cục trống. Nhưng tôi nghĩ đây là cách giải quyết. Có cách nào để dừng bố cục tải (bố cục chính) cho các giao diện một phần. Tôi không hiểu, tại sao khi không có mã để sử dụng bố cục chính, tại sao nó lại được tải. Nó giống như việc tạo một trang trong ASP.NET và thấy rằng nó kế thừa từ một trang cái mà không có chỉ thị <%@ Master ...
.Một phần xem kế thừa từ bố cục chính
Đây là xem một phần của tôi:
@* 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='[email protected]'>@padding.PadRight(level, '-') @childCategory.Title</option>
@RenderChildCategories(categories, level, childCategory.Id);
}
level--;
}
u có thể hiển thị dòng đầu tiên của trang một phần và phương thức hành động điều khiển của bạn không? –