【发布时间】:2012-06-21 17:54:35
【问题描述】:
我有一个对数据运行一些计算的控制器,然后我需要将计算返回到视图。我知道我可以通过ViewBag 完成此操作,但我想知道执行此操作的最佳实践。这些LINQ 查询是否应该在View 中执行?
public ViewResult Results()
{
var surveyresponsemodels = db.SurveyResponseModels.Include(
s => s.SurveyProgramModel).Include(s => s.PersonModel);
ViewBag.PatientFollowUpResult = db.SurveyResponseModels.Count(
r => r.PatientFollowUp);
ViewBag.ChangeCodingPractice = db.SurveyResponseModels.Count(
r => r.ChangeCodingPractice);
ViewBag.CountTotal = db.SurveyResponseModels.Count();
return View(surveyresponsemodels.ToList());
}
【问题讨论】:
-
如果我是你,我会创建一个视图将使用的视图模型。我不会在视图中进行计算。是的,gdoron 说的……
标签: c# asp.net-mvc asp.net-mvc-3 entity-framework viewbag