-1

I have tried to add multiple models in one view at asp.net MVC, but this show me error like this:

Line 1:  @using myapp.Models;
Line 2:  @model appViewModel
Line 3:  @model ForgotPasswordViewModel
Line 4:  

Can you please help me?

Tetsuya Yamamoto
  • 24,297
  • 8
  • 39
  • 61
  • try combining all models into one single view-model and import it to views. – Mustafa ASAN May 09 '18 at 07:19
  • You can't use two `@model` directive like that. See [Multiple models in a view](https://stackoverflow.com/questions/4764011/multiple-models-in-a-view) post to learn joining data models into single viewmodel. – Tetsuya Yamamoto May 09 '18 at 07:35

2 Answers2

0

You cannot directly add multiple Model to one view Instead you can do something like this (Combining all models in to a single Model)

Line 1:  @using myapp.Models;
Line 2:  @model MyMultpileViewModel
 


/**Your Model **/
class MyMultpileViewModel
{
 public AppViewModel appViewModel{get;set;} // First Model
 public ForgotPasswordViewModel forgotPasswordViewModel{get;set;}  // Second Model
}
Abhishek
  • 972
  • 3
  • 12
  • 24
  • Its Actually I have a index file and at this view file I have multiple module loading by jquery actions, but i want separate each model for each actions for example add people delete people for add people i want add a model in a separate file in models folder how can i do that – Mohammad Sumon May 09 '18 at 07:36
  • Please share your code for better understanding of your issue – Abhishek May 09 '18 at 07:38
0

Create a View Model(Class) containing both classes as members and return that as model from controller.

Gagan Deep
  • 1,508
  • 9
  • 13