如何在MVC中显示多个表中的数据? [英] How to Display Data from Multiple Tables in MVC?

查看:458
本文介绍了如何在MVC中显示多个表中的数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我目前正在学习MVC 3.0,并已在表上执行了基本的任务插入,更新等.现在,我将在一个视图中显示来自多个表(Order和OrderDetail)的数据,并且还希望从一个视图中将数据插入两个表中.请指导我该怎么做?

Hi,
I am currently learning MVC 3.0 and have performed basic tasks insert, update etc on on table. Now I was to display my data from multiple tables ( Order and OrderDetail) in one view and also want to insert data in two tables from one view. Please guide me how can I do this? Please don''t refer to MVC tutorial link just guide me if you grap up the idea?

推荐答案

简单来说,您需要使用以下SQL语句选择数据,连接两个表并获取您需要的数据.如果您编写自己的SQL,也可以将数据插入到任意数量的表中.
Simply, you need to select your data with a SQL statement that joins the two tables and gets the data you need. You can also insert data in to as many tables as you want, if you write your own SQL to do it.


通过使用sql server join,您可以轻松地从不同的表中获取数据,并且您想要将数据插入不同的表中,可以使用poco类概念将不同的字段数据插入不同的表中.


谢谢
Saurav Sharma
By using sql server joins you can easy get data from different tables and if you want to insert data in different table you can use the poco class concept for different fields data to insert in different tables.


Thanks
Saurav Sharma


您需要创建一个ViewModel,在其中创建两个表的实例,并在创建视图时引用视图模型而不是模型.
您可以使用VM访问两个表.

-萨加尔·索兰基(Sagar Solanki)
You need to create a ViewModel in which you make instance of both tables and while creating a view refer the view model instead of model.
you can access both tables using the VM.

-Sagar Solanki


这篇关于如何在MVC中显示多个表中的数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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