I have a grid that has multiple DropDownLists. All of the DropDownLists are populated using the ViewData object. In this case, I have a DropDownList that I would actually like it to populate multiple other columns in the Grid. I am not sure how I can access the other information in the ViewData object. So the Project_Key and the NameDesc columns in the model are for the dropdown. But, the other columns Mgt_Unit_Key, Program_Key and Zone_Key are columns in the ViewData that I want to use to populate (default) other columns in the grid to. How can I access these other columns in the ViewData and assign them to columns in the grid?
Here is the basics of my controller:
public ActionResult TimecardIndex()
{
ViewData["Projects"] = this.projectservice.GetDropDownList();
return View();
}
The grid looks like:
@(Html.Kendo().Grid<IRISWeb.Models.CAS.Timecard>()
.Name("Grid")
.Columns(c =>
{
c.Command(command => { command.Destroy(); }).Width(120).Lockable(true).Locked(true);
c.Bound(p => p.Task_Date).Width(120).Lockable(true).Locked(true).EditorTemplateName("IRISDate");
c.ForeignKey(p => p.Activity_Key, (System.Collections.IEnumerable)ViewData["Activities"], "Activity_Key", "NameDesc").Width(350).Lockable(true);
c.ForeignKey(p => p.Project_Key, (System.Collections.IEnumerable)ViewData["Projects"], "Project_Key", "NameDesc").Width(350);
c.ForeignKey(p => p.ProjectSub_Key, (System.Collections.IEnumerable)ViewData["ProjectSubs"], "ProjectSub_Key", "NameDesc").EditorTemplateName("ProjectSub").Width(200);
c.ForeignKey(p => p.Mgt_Unit_Key, (System.Collections.IEnumerable)ViewData["Mgt_Units"], "Mgt_Unit_Key", "NameDesc").Width(350);
c.ForeignKey(p => p.Program_Key, (System.Collections.IEnumerable)ViewData["Programs"], "Program_Key", "NameDesc").Width(350);
c.ForeignKey(p => p.Zone_Key, (System.Collections.IEnumerable)ViewData["Zones"], "Zone_Key", "NameDesc").Width(350);
c.ForeignKey(p => p.Road_Key, (System.Collections.IEnumerable)ViewData["Roads"], "Road_Key", "FullRoadNumber").Width(200);
.....
The model for the ProjectDropDown returned by the GetDropDownList() is:
public class ProjectDropDown
{
[Key]
[ScaffoldColumn(false)]
public string Project_Key { get; set; }
[MaxLength(70)]
[Display(Name = "Name")]
public string NameDesc { get; set; }
[MaxLength(10)]
[Display(Name = "Mgt. Unit")]
public string Mgt_Unit_Key { get; set; }
[MaxLength(10)]
[Display(Name = "Program")]
public string Program_Key { get; set; }
[MaxLength(10)]
[Display(Name = "Zone")]
public string Zone_Key { get; set; }
[MaxLength(10)]
[Display(Name = "Road")]
public string Road_Key { get; set; }
}
Here is the basics of my controller:
public ActionResult TimecardIndex()
{
ViewData["Projects"] = this.projectservice.GetDropDownList();
return View();
}
The grid looks like:
@(Html.Kendo().Grid<IRISWeb.Models.CAS.Timecard>()
.Name("Grid")
.Columns(c =>
{
c.Command(command => { command.Destroy(); }).Width(120).Lockable(true).Locked(true);
c.Bound(p => p.Task_Date).Width(120).Lockable(true).Locked(true).EditorTemplateName("IRISDate");
c.ForeignKey(p => p.Activity_Key, (System.Collections.IEnumerable)ViewData["Activities"], "Activity_Key", "NameDesc").Width(350).Lockable(true);
c.ForeignKey(p => p.Project_Key, (System.Collections.IEnumerable)ViewData["Projects"], "Project_Key", "NameDesc").Width(350);
c.ForeignKey(p => p.ProjectSub_Key, (System.Collections.IEnumerable)ViewData["ProjectSubs"], "ProjectSub_Key", "NameDesc").EditorTemplateName("ProjectSub").Width(200);
c.ForeignKey(p => p.Mgt_Unit_Key, (System.Collections.IEnumerable)ViewData["Mgt_Units"], "Mgt_Unit_Key", "NameDesc").Width(350);
c.ForeignKey(p => p.Program_Key, (System.Collections.IEnumerable)ViewData["Programs"], "Program_Key", "NameDesc").Width(350);
c.ForeignKey(p => p.Zone_Key, (System.Collections.IEnumerable)ViewData["Zones"], "Zone_Key", "NameDesc").Width(350);
c.ForeignKey(p => p.Road_Key, (System.Collections.IEnumerable)ViewData["Roads"], "Road_Key", "FullRoadNumber").Width(200);
.....
The model for the ProjectDropDown returned by the GetDropDownList() is:
public class ProjectDropDown
{
[Key]
[ScaffoldColumn(false)]
public string Project_Key { get; set; }
[MaxLength(70)]
[Display(Name = "Name")]
public string NameDesc { get; set; }
[MaxLength(10)]
[Display(Name = "Mgt. Unit")]
public string Mgt_Unit_Key { get; set; }
[MaxLength(10)]
[Display(Name = "Program")]
public string Program_Key { get; set; }
[MaxLength(10)]
[Display(Name = "Zone")]
public string Zone_Key { get; set; }
[MaxLength(10)]
[Display(Name = "Road")]
public string Road_Key { get; set; }
}