0

I have a student details page which i want to display student details, course details and another related informations on a single page. The reason for requiring to pass and display multiple models is that i am doing the project from an existing and operational database, so no way to update related structures and have them as a single model.

Is there any other way passing multiple IEnumrable<Model> values to a razor view with return view(model1, model2) of which are the result sets returned from two tables using a unique identifier columns selection.

smned
  • 663
  • 1
  • 6
  • 19
  • You can only pass one model to a view. Create a view model containing the properties you want. –  Apr 26 '18 at 08:41
  • There is no way to pass multiple model objects, however, a single model is always sufficient as you can create a composite model class that has multiple properties pointing to multiple model parts. – Wiktor Zychla Apr 26 '18 at 08:42
  • You should use a view model. A new class that will contain all the data your view want. – CodeNotFound Apr 26 '18 at 08:42
  • I think it's not possible to return more than one viewmodel. You need to combine result sets from tables (i.e. data models) in a single viewmodel and pass it to view. – Tetsuya Yamamoto Apr 26 '18 at 08:45
  • @CodeNotFound Yes, but i am having trouble creating a view model as my models are automatically generated from an existing database. Is it possible to do that with this approach? – smned Apr 26 '18 at 09:03

1 Answers1

0

You can't pass multiple model in razor. But you can combine your all model in single model and pass that model to your view and can retrieve value from each of the model(class) to view and bind data.

Kevin Shah
  • 1,589
  • 1
  • 13
  • 20
  • Creating modelviews in ADO.NET generated models kept giving me errors, is it possible to add models to database generated models? may be a link to demonstration? as creating new model class is not working for me. – smned Apr 26 '18 at 08:48