我如何从多个表中选择并将结果返回到视图mvc 5

问题描述 投票:0回答:1

我正在尝试在我的索引视图中显示此查询的结果,但是它正在报告错误,我已经尝试调试它,没有成功,如果有人可以帮助让我知道我哪里出了问题,我将不胜感激。

    public ActionResult Index()
    {           
       var users =
        (from u in db.Users
                     join s in db.States
                         on u.StateId
                         equals s.StateId

                     join l in db.Lgas
                         on u.LgaId
                         equals l.LgaId
                     select new
                     {
                         u.Surname,
                         u.Firstname,
                         u.Othernames,
                         u.Email,
                         s.StateName,
                         l.LgaName
                     }).ToList();


        return View(users);
    }
asp.net-mvc entity-framework-5
1个回答
1
投票

您不能将匿名对象传递给View,因为标记为internal和View的匿名对象的每个属性都在不同的命名空间中。 Here is great explanation

© www.soinside.com 2019 - 2024. All rights reserved.