0

Within Razor is it possible for me to add another model, I currently have

@model Models.ListModel

I would like to add another model into the razor view e.g.

@model2 Model.PostModel
Sweb
  • 15
  • 1
  • 5
  • 4
    No. You need to create a view model containing properties for each model –  May 01 '18 at 08:30
  • Make a new model that contains both models. Like `class MasterModel { public class ListModel{} public class PostModel{}`. You can access each model like `MasterModel.ListModel`. `Model.ListModel`; if you are having individual process for both models on single page, then make two partial views and render them on the page. – DhavalR May 01 '18 at 08:32

1 Answers1

0

Create a ViewModel with both the classes inside it Example:

public class PostListViewModel
{
    public List ListModel{ get; set; }
    public Post PostModel{ get; set; }
}