c# - ASP.NET MVC 4 How to pass multiple objects through the same controller to a view? -


in asp.net mvc4 web application i'm trying display table information sql database using entity framework. generating view sql table(using database firs ef) easy me do, i'm stuck on more conceptual question. right controller passes list of entity objects view.

 public actionresult index() {     return view(db.apu_daily_summary_test.tolist()); } 

but need calculate min , max of of these columns in sql. know should calculate min , max inside model, after don't know how should pass information through controller view. need view model? api? controller?

you described perfect use case view model.

here's structure recommend:

public class myviewmodel {     public int maxofcolumn { get; set; }     public list<innerviewmodel> items { get; set; } }  public class innerviewmodel {     // create properties here represent model's columns need display } 

not view model break don't have many data operations within view. breaks common bug more complex models ef object has circular reference.


Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -