In my web application, there are two types of data I need to show in the html view in different tables.
So First I created two different view models to store data.
So in the controller I have wrote this code to send the data to view models
List < RecognizedPartsViewModel > Reco = new List < RecognizedPartsViewModel > ();
var rData = (from i in db.InventoryMain join p in db.PartCategory on i.PartCatogary equals p.Id where i.ReOrderQty != 0 && i.AvaQty <= i.ReOrderQty && i.PartCatogary != 0 select new RecognizedPartsViewModel {
PartNo = i.PartNo,
Description = i.PartDescription,
Model = i.PartModel,
AvaQty = i.AvaQty,
ReOrderQty = i.ReOrderQty,
PartCato = i.PartCatogary,
ABCD = i.A_B_C_D_Category
}).ToList();
List < UnRecoPartsViewModel > unReco = new List < UnRecoPartsViewModel > ();
var rUnData = (from i in db.InventoryMain where i.ReOrderQty != 0 && i.AvaQty <= i.ReOrderQty && i.PartCatogary == 0 select new UnRecoPartsViewModel {
PartNo = i.PartNo,
Description = i.PartDescription,
Model = i.PartModel,
AvaQty = i.AvaQty,
ReOrderQty = i.ReOrderQty,
ABCD = i.A_B_C_D_Category
}).ToList();
So I need to know that this data I have to show in the same html view. So how can I call these two view model as separate list in the html view?
2
Answers
You need to create another model that can take both types of data, that is 1
List < RecognizedPartsViewModel >
and 1List < UnRecoPartsViewModel >
and you would pass this model to your view and access each one of your lists using this modelIf your data model has structure described in the question you can use the one class for two cases:
And then create a new class to included separated list for each category:
Then: