【发布时间】:2010-10-06 13:35:01
【问题描述】:
我有这个有效的代码。
public class HelloWorldController : Controller
{
UAStagingEntities db = new UAStagingEntities();
public ActionResult Index(int? id)
{
var depot = db.CSLA_DEPOT.Where(c => c.DEPOT_ID == id.Value);
return View(depot.ToList());
}
}
我不知道如何显示一个包含两个查询结果的视图。我将如何创建视图以显示仓库和地址?以及如何编写 return 语句?
public class HelloWorldController : Controller
{
UAStagingEntities db = new UAStagingEntities();
public ActionResult Index(int? id)
{
var depot = db.CSLA_DEPOT.Where(c => c.DEPOT_ID == id.Value);
var Address = db.CSLA_ADDRESS.Where(a => a.CSLA_DEPOT.DEPOT_ID == id.Value);
return View(depot.ToList());
}
}
编辑 *
我添加了这个模型
namespace CustomerCareMVC.Models
{
public class CSLA_StagingModel
{
public List<CSLA_DEPOT> depots { get; set; }
public List<CSLA_ADDRESS> addresses { get; set; }
}
}
并在控制器中添加了这个方法
public ActionResult ShowAllTables()
{
var model = new CSLA_StagingModel()
{
depots = db.CSLA_DEPOT.Where(c => c.DEPOT_ID == 10065),
addresses = db.CSLA_ADDRESS.Where(a => a.CSLA_DEPOT.DEPOT_ID == 10065),
};
return View(model);
}
我在这两行下面得到了波浪线
depots = db.CSLA_DEPOT.Where(c => c.DEPOT_ID == 10065),
addresses = db.CSLA_ADDRESS.Where(a => a.CSLA_DEPOT.DEPOT_ID == 10065),
带有此错误消息
错误 1 无法将类型“System.Linq.IQueryable”隐式转换为“System.Collections.Generic.List”。存在显式转换(您是否缺少演员表?) C:\CustCareMVC\CustomerCareMVC\CustomerCareMVC\Controllers\HelloWorldController.cs 59 26 CustomerCareMVC
【问题讨论】:
标签: asp.net-mvc-2