我有一个对数据运行一些计算的控制器,然后我需要将计算返回到视图。我知道我可以通过 来完成此操作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());
}