如何在mvc5中的同一视图中使用两个模型 [英] How to use two models in the same view in mvc5

查看:62
本文介绍了如何在mvc5中的同一视图中使用两个模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在同一个视图中使用两个不同的。如何做到这一点?

可能有一种情况,一个模型可能有两个不同的类或两个模型。

请告诉我如何在上述两个场景中的同一视图中使用它。

I want to use two different in the same view .How to do that ?
There may be the scenario that one model could have two different classes or two models .
Please tell me that how to use that in the same view in both the mentioned scenario.

推荐答案

在一个视图中使用多个模型是不可能的。



但是有一个解决方法:



您可以使用所谓的ViewModel,它结合了您想要使用的模型





有一篇好文章描述它:

ASP.NET MVC 4 / MVC 5视图中的多个模型 [ ^ ]
Using more than one model in one view is not possible.

But there is a workaround:

You can use a so-called ViewModel which combines the models
you want to use.

There is a good article describing it:
Multiple Models in a View in ASP.NET MVC 4 / MVC 5[^]


这篇关于如何在mvc5中的同一视图中使用两个模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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