0

I have several controller and views, I want to pass view model and partial view model to the view and a partial view (display some debug information) which is rendered in the shared layout view.

option 1 which I believe it is working but I'm not sure if it is good approach(Please confirm).

Create layout view model and include all the other view models for different views and the view model for the partial view.

Public class layout
{
     public PartialViewModel A;
     public ViewModel B
     public ViewModel C 
     .....(depends on how many view models I have)
}

Define the layout view model in shared layout view pass the partial view model to partial view. In controller get and post action initialize the Layout view and pass the layout view along.

Option 2 I don't know how it would work, but if it works, that would be cool In each view model, I will define the partial view model in it. I will pass the view model and partial view model along, but in the shared layout view, how can I pass the partial view model to the partial view?

Thanks

MstfAsan
  • 3,591
  • 2
  • 20
  • 32

1 Answers1

0

Similar to ASP.NET MVC Razor pass model to layout and I'll echo the sentiment...

It might be a bad idea to type the layout view, and ASP .NET MVC doesn't really give you a lot of options in this scenario because of that. But what you can do is have a view model base that all your view models inherit from, and make that your type on _Layout.

Community
  • 1
  • 1
Erik Elkins
  • 621
  • 5
  • 13