質問、回答、回答へのコメント、および質問へのコメントを表示するビューがあります。
すべてのデータを表示するには、次のようなものを使用します。
[HttpGet, ChildActionOnly]
public PartialViewResult RenderQuestion(int questionId, int page, int pageSize, string sort)//For question display
{
var question = questionsService.GetQuestion(questionId);
var author = userService.GetUser(question.AuthorId);
var commentIds = commentService.GetTopCommentIds(questionId, int.MaxValue, CommentType.Question);
var answerIds = answerService.GetAnswerIdsByQuestion(page, pageSize, questionId, sort);
var model = new QuestionModel{ Question = question, Author = author, CommentIds = commentIds, AnswerIds = answerIds}
return PartialView("_Question", model);
}
[HttpGet, ChildActionOnly]
public PartialViewResult RenderAnswer(int answerId)
{
var answer = answerService.GetAnswer(answerId);
var author = userService.GetUser(answer.AuthorId);
var commentIds = commentService.GetTopCommentIds(answerId, int.MaxValue, CommentType.Answer);
var model = new AnswerModel { Answer = answer, Author = author, CommentIds = commentIds};
return PartialView("_Answer");
}
[HttpGet, ChildActionOnly]
public PartialViewResult RenderComment(int commentId, CommentType commentType)
{
var comment = commentService.GetComment(commentId, commentType);
var author = userService.GetUser(comment.AuthorId);
var model = new CommentModel { Comment = comment, Author = author};
return PartialView("_Comment");
}
そして、たとえば質問の私の部分的なビューでは、ループを繰り返してModel.AnswerIds
呼び出し@{ Html.RenderAction("RenderAnswer", new {answerId}) };
、Model.CommentIdsを呼び出して呼び出します@{ Html.RenderAction("RenderComment", new {commentId}) };
@Html.RenderAction
知りたいのですが、これはビュー分解の良い方法であり、この方法は頻繁に呼び出されるパフォーマンスに悪影響を及ぼしますか?