简体   繁体   中英

ASP.Net MVC Dashboard View. Where to perform aggregations

I have read a few other stackoverflow posts regarding dashboard setup in a view, but I am still struggling a bit. I have one master query that is returning a detailed view of my data, since I only want to hit the database once. So I have a Controller Action called GetEmployeeInfo() that returns a IEnumerable<EmployeeBase> model class. I want to be able to take this class and break it apart into different divs in a view. For example, I would have three divs on top of the View aggregating row count by employee category and 2 divs on the botton that shows the detailed table. Can this be accomplished strictly through one view by setting up conditional/aggregate statements all over or do I use partial views or something else. Or is using one controller action a problem?

Thank you.

I used the answer from Pat Burke (see comments under my question. I posted it below as well). I created one base class and one partial view for my employee categories that has all the properties I needed. I did the same for my detail portion. Then I created the DashboardViewModel which had 3 IEnumerable<EmployeeCategoryBase> properties as well as 2 IEnumerable<EmployeeDetailInfo> properties. Then I created a strongly typed DashboardViewModel view with 5 divs that used @{Html.RenderPartial(ViewName,model.property);}

Another alternative is to have your Dashboard view strongly typed to a View Model like "DashboardViewModel" which is composed of different collections which correspond to the data needed for each sub-part. This would also put the aggregation logic to the server-side rather than on the client in JS. You could even have partial views included, each of which corresponds to a sub-part and a collection of data in your View Model. It's good practice to have your view model directly correlate to the data needed by your view

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM