Hello mates,
How to use two viewmodel class in one view, i have to use both viewmodels in view not in constructor
Hello mates,
How to use two viewmodel class in one view, i have to use both viewmodels in view not in constructor
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Saravanan GanesanPosted Sep 25, 2023, 5:42 PM
To use two ViewModel classes in one view in a technology like ASP.NET Core MVC, create a composite ViewModel that includes properties for both ViewModels, then use that composite ViewModel in your view. This way, you can access data from both ViewModels within the same view without modifying constructors.
Jignesh KumarPosted Jan 23, 2023, 3:49 AM
Hello,
Please follow below link which will help you out,
https://www.c-sharpcorner.com/article/managing-data-with-viewmodel-in-asp-net-mvc/
Rajanikant HawaldarPosted Jan 22, 2023, 2:25 PM
Like below code
Pasang TamangPosted Jan 21, 2023, 1:50 PM
Hi,
You have to use one main view model that holds your view models. Check below code example
You have to find MainViewModel in your view and then while binding individual property you should be able to do it like First.FirstName, Second.Address and so on.
Regards,
Pasang