I have an stored procedure which brings the data in this fashion. I need this to be grouped and assigned to a list. How to do this?
+------------+---------+------------+------------+
| 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 |
+------------+---------+------------+------------+
My model looks something like this
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; }
}
As if now I'm assigning the values like this
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);
}
And I'm showing the value in kendo grid in my view. I want to display the Template under a multiselect control. How can I group by and assign a value to List?