How can I call three models in a view in MVC? [Resolved]

Posted by Jitendrasoft09 under ASP.NET MVC on 7/1/2017 | Points: 10 | Views : 375 | Status : [Member] [MVP] | Replies : 2
I have created three models and wanted to call three models in a view. How we can do this one?

Jitendra Kumar
If my post helps you, plz mark as an answer.



Responses

Posted by: A2H on: 7/1/2017 [Member] [MVP] Silver | Points: 50

Up
0
Down

Resolved
You can use ViewModel to hold data from three models and then pass it on to view
You can check the below links for more details
http://www.dotnetfunda.com/forums/show/20853/how-do-i-display-data-from-a-view-in-the-database
http://sampathloku.blogspot.com/2012/10/how-to-use-viewmodel-with-aspnet-mvc.html

Thanks,
A2H
My Blog

Jitendrasoft09, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Shreedar on: 9/21/2017 [Member] Starter | Points: 25

Up
0
Down
public class CountryList
{
public int CountryId { get; set; }
public string Country { get; set; }
public int StateId { get; set; }
public string State { get; set; }
}

public class CustomerDetails
{
public int ClientId { get; set; }
public string Name { get; set; }
public string MobileNo { get; set; }
}

public class ProductDetails
{
public int ProductId { get; set; }
public string ProductName { get; set; }
}

public class viewmodel
{
public IEnumerable<CustomerDetails> _cDetails { get; set; }
public IEnumerable<CountryList> _cList { get; set; }
public IEnumerable<CountryList> _pDetails { get; set; }
}



From the above code when you pass viewmodel to view, then you can use _cDetails or _cList or _pDetails as per the requirement.

Regards

Sridhar Thota.
www.dotnet-sridhar.blogspot.com

Jitendrasoft09, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response