【问题标题】:MVC3 Model Data PopulationMVC3 模型数据填充
【发布时间】:2013-12-06 22:56:45
【问题描述】:

我使用 Code First 所以它创建了实体并生成了 dbset 并使用 LINQ 来实现我的数据。我是 LINQ 新手,我想了解以下内容

这是我的一张桌子我的模型

namespace MISSanctions.Models
{
using System;
using System.Collections.Generic;

public partial class tbl_navigation_menus
{
    public long tbl_nav_id { get; set; }
    public string tbl_controller { get; set; }
    public string tbl_method { get; set; }
    public string tbl_menu_name { get; set; }
    public long tbl_parent_id { get; set; }
    public string tbl_view { get; set; }
    public long tbl_child_id { get; set; }
    public byte tbl_active { get; set; }
  }
}

它与表 tbl_nav_rights 有关系

 namespace MISSanctions.Models
{
using System;
using System.Collections.Generic;

public partial class tbl_nav_rights
{
    public long tbl_nav_right_id { get; set; }
    public long tbl_user_id { get; set; }
    public long tbl_nav_id { get; set; }
    public long tbl_nav_active { get; set; }
}
}

我想选择 tbl_user_id 的权限为 11796 。意味着 11769 将拥有多个权限,我想将上面的 tbl_navigation_menus 加入表格,其中包含导航名称控制器名称和方法以及一些图标图像。

我想创建一个单独的模型,它返回用户 ID 11769 的数据。我正在创建一个这样的模型,但对如何获取模型中的多行感到困惑

这是将返回给视图的主导航模型

namespace MISSanctions.Models
{
public class AdminNavigationList
{
    public int Userid {get;set;}
    public int tbl_nav_id{get;set;}
    public string tbl_controller { get; set; }
    public string tbl_method { get; set; }
    public string tbl_menu_name { get; set; }
    public int tbl_parent_id { get; set; }
    public bool active { get; set; }
    public string tbl_icon { get; set; }
}

}

然后我将循环显示导航..请帮助我实现它

【问题讨论】:

    标签: c# asp.net asp.net-mvc-3 linq


    【解决方案1】:

    你必须设置 tbl_nav_menus 表与 tbl_nav_rights 的关系 并且 nav_menu 表包含 nav_right 表的多个条目, 那么你必须添加

    公共部分类 tbl_navigation_menus { public Ilist tbl_nav_rights{get;set;}

    }

    检查一次..

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-01-29
      • 1970-01-01
      • 1970-01-01
      • 2021-06-30
      • 2013-10-26
      • 1970-01-01
      • 2014-12-13
      • 2014-06-11
      相关资源
      最近更新 更多