分组并为列表分配值

时间:2016-06-03 10:23:40

标签: c# linq kendo-grid asp.net-mvc-5 kendo-multiselect

我有一个以这种方式提供数据的存储过程。我需要将其分组并分配给列表。怎么做?

+------------+---------+------------+------------+
|   RuleID   |RuleName | TemplateId |TemplateName|
+------------+---------+------------+------------+
| 1          | R1      |  1         | T1         |
| 1          | R1      |  2         | T2         |
| 1          | R1      |  3         | T3         |
| 1          | R1      |  4         | T4         |
| 2          | R2      |  1         | T1         |
| 2          | R2      |  2         | T2         |
+------------+---------+------------+------------+

我的模型看起来像这样

public class MergeRulesGridModel
{
    public int RuleID { get; set; }
    public string RuleName { get; set; }
    public TemplateListModel TemplateList { get; set; }
}

public class TemplateListModel
{
    public int TemplateId { get; set; }
    public string TemplateName { get; set; }
}

好像现在我正在分配像这样的值

public ActionResult ReadMergeRules([DataSourceRequest] DataSourceRequest request)
{
    //Get 
    var siteList = _unitOfWork.EmailManagementRepository.GetMergeRulesAndStrategy().Select(t => new MergeRulesGridModel
    {
        RuleID = t.RuleID,
        RuleName = t.RuleName,
        TemplateList = new TemplateListModel { TemplateId = t.TemplateId, TemplateName = t.TemplateName }
    }).ToList();

    // Flatten the account to avoid circular references during JSON serialization
    DataSourceResult result = siteList.ToDataSourceResult(request, item => new
    {
        item.RuleID,
        item.RuleName,
        item.TemplateList
    });

    return Json(result);
}

我在视图中显示了剑道网格中的值。我想在多选控件下显示模板。如何分组并为List分配值?

0 个答案:

没有答案