나는 다음 뷰 모델이 있습니다면도기 뷰에 재귀 함수를 작성하는 방법은 무엇입니까?
public class AllQuestionsInCategoriesViewModel
{
public string Category_Name { get; set; }
public string Category_Number { get; set; }
public List<ShowQuestionViewModel> questions { get; set; }
public List<AllQuestionsInCategoriesViewModel> SubCategories { get; set; }
public AllQuestionsInCategoriesViewModel()
{
questions = new List<ShowQuestionViewModel>();
SubCategories = new List<AllQuestionsInCategoriesViewModel>();
}
}
나는이 스레드 다음 봤는데을 :
ASP.NET MVC 3 Razor recursive function
그리고 나는이 코드를 사용하여 결국 :
이@model List<MvcApplication3.Models.ViewModels.Category.AllQuestionsInCategoriesViewModel>
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<title>PrintSchema</title>
<link type="text/css" href="../../Content/Print.css" rel="Stylesheet" />
</head>
<body>
@{
foreach(var cq in Model) {
ShowSubItems(cq);
}
}
@helper ShowSubItems(MvcApplication3.Models.ViewModels.Category.AllQuestionsInCategoriesViewModel MyObj)
{
<h1>@MyObj.Category_Number @MyObj.Category_Name</h1>
foreach (var question in MyObj.questions)
{
@Html.DisplayFor(x => question, question.GetType().Name + "Print")
}
if (MyObj.SubCategories.Count != null || MyObj.SubCategories.Count != 0)
{
foreach(var subitem in MyObj.SubCategories)
{
ShowSubItems(subitem);
}
}
}
</body>
</html>
문제는 ShowSubItems 메서드는 아무 것도 표시하지 않습니다. 모델이 비어 있지 않으며보기가 ShowSubItems 메서드 외부에서 @Html.DisplayFor(x => x.question, question.GetType().Name + "Print")
으로 잘 표시 될 수 있습니다. 그러나 ShowSubItems 메서드의 뷰에 렌더러를 가져 오는 것은 없습니다. 어떻게 됐니?
이 질문을 잊지하시기 바랍니다. 나는 출력을 렌더링하는 것을 잊었다. – Kenci