Asp.net mvc 如何在强类型视图中包含多个模型对象?

Asp.net mvc 如何在强类型视图中包含多个模型对象?,asp.net-mvc,object,Asp.net Mvc,Object,从ActionResult函数创建强类型视图时,用于创建视图的Visual Studio对话框仅允许包含一个模型对象 我如何包含1个以上的项目,以便对所有项目使用intelli sense?这是不可能的。您应该创建另一个模型来包装这两个模型 例如: //Model public class FooModel1 { public string Property {get;set;} } public class FooModel2 { public string Property

从ActionResult函数创建强类型视图时,用于创建视图的Visual Studio对话框仅允许包含一个模型对象


我如何包含1个以上的项目,以便对所有项目使用intelli sense?

这是不可能的。您应该创建另一个模型来包装这两个模型

例如:

//Model

public class FooModel1
{
   public string Property {get;set;}
}

public class FooModel2
{
   public string Property {get;set;}    
}

public class FooModel
{
  public FooModel1 One {get;set;}
  public FooModel2 Two {get;set;}
}
//控制器:

public ActionResult Index()
{
   var model = new FooModel() { One = new FooModel1 (), Two = new FooModel2 ()};
   return View(model);
}
//看法

@model FooModel
@Html.TextBoxFor(m=>m.One.Property)
@Html.TextBoxFor(m=>m.Two.Property)