c# - Merge a list of viewmodels into one -


i not sure if asking correctly, i'll best explain , provide code.

i have actionresult on controller loops through every year available, prints out results each year id, , loops through until it's finished, produces final product.

the problem having sorting feature. sorts via every year instead of whole thing table. figured easiest way of fixing 1 model instead of multiple separated year somehow merge list one.

i pretty new c# mvc, helpful tips, tricks , examples immensely. if need other code please ask , provide it.

controller

// list of models, because want of them             var managementmodels = new list<collectionsmanagementviewmodel>();             var setupids = _repository.getallyearsetupids();              foreach (var setupid in setupids)             {                 // new model created each setup id                 var managementmodel = _repository.getoverduebalances(type,page, pagelength,                          setupid.yearsetupid, balancefilter,                          sort, direction == constants.ascending,                          spreadsheettype);                  managementmodel.title = title + " management";                 managementmodels.add(managementmodel); // add model list             }              // pass collection view              return view("collectionsmanagement", new overpayviewmodel { collectionsmanagementviewmodels = managementmodels}); 

edit have table in view sorted via column clicked on. currently, when column name selected, sorts keeps in years, example 4,5,6 in year 2015 sorted 4,5,6. in year 2016 have 1,2,3 , when sort column doesn't sort 1,2,3,4,5,6 sorts it, 4,5,6,1,2,3 because it's sorting every year , not whole table.

your question little vague (e.g. _repository backed etc).

but assuming you're getting bunch of these collectionsmanagementviewmodels, , want sort them year before displaying them:

return view("collectionsmanagement",      new overpayviewmodel {          collectionsmanagementviewmodels =              _repository             .getallyearsetupids()             .select(ysi => _repository.getoverduebalances(                 type,                 page,                 pagelength,                 ysi.yearsetupid,                 balancefilter,                 spreadsheettype)    // assuming sort optional             .orderby(vm => vm.year) // assuming vm has more sensible year property sort numerically     }); 

i really having make lot of assumptions code, please see how create minimal, viable, complete example better familiarise how you're best answer here.


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -