@model .Models.somemodel1. this is one view data.
@model .Models.somemodel2. this is another view data.
如何将两个模型合并到一个视图中?
答案 0 :(得分:2)
创建一个viewmodel包装类,然后在视图中使用它。阅读What is ViewModel in MVC?
public class MyViewModel
{
public SomeModel1 someModel1{get;set;}
public SomeModel2 someModel2{get;set;}
}
在您的视图中
@model MyViewModel
<div>Model.someModel1.Property</div>
答案 1 :(得分:0)
你可以使用元组
在视图中
@model Tuple<Model1, Model2>
// You can access the model values like
@Model.Item1.FirstName
@Model.Item2.Mark
控制器
Model1 m1 = new Model1();
Model2 m2= new Model2();
var tuple = new Tuple<Model1,Model2>(m1,m2);
return View(tuple);
了解更多详情
http://msdn.microsoft.com/en-us/library/dd268536(v=vs.110).aspx