如何在mvc entityframework中使用2表和2模型类创建列表

编程入门 行业动态 更新时间:2024-10-28 02:22:53
本文介绍了如何在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模型类创建列表

本文发布于:2023-11-08 16:32:51,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1569894.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:模型   如何在   列表   entityframework   mvc

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!