如何在mvc entityframework中使用2表和2模型类创建列表 [英] How to create a list using 2 table and 2 model class in mvc entityframework

查看:59
本文介绍了如何在mvc entityframework中使用2表和2模型类创建列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

how to create a list using 2 table and 2 model class in mvc entityframework







这里我不想创建另一个模特类

假设

modelclass 1

int nameid

string name1



model class2

int id2

字符串的位置

i需要一个列表,它应该采用nameid并从模型类和相应的clumn中放置相应的clumn值。



我尝试了什么:



无法返回列表,我不想创建我想要的任何模型类使用现有的




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

推荐答案

如果要创建类型列表,则必须在List中指定类型。例如,您需要Model Class 1的列表,然后您必须说List< modelclass1> ;.

在您的情况下,您必须创建一个ModelView类。



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.

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





这里你没有创建一个新的模型类,而是一个视图模型类来处理视图。



这是MVC的做事方式。



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.


这篇关于如何在mvc entityframework中使用2表和2模型类创建列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆