Click here to Skip to main content
15,919,879 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
C#
how to create a list using 2 table and 2 model class in mvc entityframework



here i dont want to create another model class
suppose
modelclass 1
int nameid
string name1

model class2
int id2
string place
i want a list it should take nameid and place value from model class and respective clumn from respective table.

What I have tried:

unable to return list ,i dont want to create anyothe model class i want to use the existing one
Posted
Updated 22-Feb-16 1:27am
v2

1 solution

If you want to create a list of a type then you have to specify the type in List. For example , you want list of Model Class 1 then you have to say List<modelclass1>.
In your case, you have to create a ModelView class.

C#
public class ModelViewClass
{
    public int nameid {get;set;}
    public string place {get;set;}
}


Here you are not creating a new model class but a view model class to work with view.

This is the MVC way of doing things.
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900