【发布时间】:2012-01-31 21:01:45
【问题描述】:
我有显示问题、答案、对答案和问题的评论的视图。
要显示我想使用的所有数据,如下所示:
[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调用造成的性能产生不良影响。
【问题讨论】:
标签: asp.net-mvc asp.net-mvc-3 renderaction