Home > Mobile >  How to show multiples model data in one view in mvc.net?
How to show multiples model data in one view in mvc.net?

Time:11-22

I have built-in models in my project and I want to show data of all the models in one view
in table form by using one model. I am using Entity Frame work.

CodePudding user response:

What you are describing is a ViewModel - which allows you to group multiple properties and models into one, for use in a view.

For example, say you have 2 models

Model1.cs
Model2.cs

If you want to use both in a view, you can create a new model called "ViewModel1.cs" and set it up like this:

public class ViewModel1
{
    public Model1 model1 { get; set; }
    public Model2 model2 { get; set; }
}

You can then reference this ViewModel at the top of your view with:

@model ViewModel1.cs

Allowing you to access both Model1 and Model2 in your view.

  • Related