Hi Konstantin,
I have attempted the solution again, this time by removing the .Virtual functionality from the template and re-applying the .set method in the JS code to no avail. I am satisfied with my previous solution.
Thank you for your help. Much appreciated!
Here is my snippets for review. Maybe something is off.
Controller:
public
JsonResult Get_SimpleCourseList()
{
return
Json(_service.Get_Courses(
false
).Select(c =>
new
CourseSimple(c)).OrderBy(c => c.CourseTitle), JsonRequestBehavior.AllowGet);
}
View
@(Html.Kendo().Grid<LMS_Web_MVC.Models.ClassFull>()
.Name(
"grid_#=CourseID#"
)
.ToolBar(t => t.Create().Text(
"Add Class"
))
.Columns(columns =>
{
columns.Bound(o => o.ClassID);
columns.Bound(o => o.BeginDate).Format(
"{0:yyyy-MM-dd HH:mm}"
);
columns.Bound(o => o.EndDate).Format(
"{0:yyyy-MM-dd HH:mm}"
);
columns.Bound(o => o.Enrollees);
columns.Bound(o => o.Active);
columns.Command(c => { c.Edit(); }).Title(
"Actions"
);
})
.Editable(e => e.Mode(GridEditMode.PopUp).Window(w => w.Width(600)).TemplateName(
"ClassEditor"
))
.Events(ev => ev.Edit(
"onNewCourseClass"
))
View Function
function
onNewCourseClass(e) {
if
(e.model.ClassID ==
null
) {
var
courseGrid = $(
"#grid"
).data(
"kendoGrid"
);
var
parentRow = courseGrid.dataItem(
this
.wrapper.closest(
"tr"
).prev());
var
id = parentRow.CourseID;
e.model.set(
"CourseID"
, id);
}
}
ClassEditor Template
<div data-container-
for
=
"CourseID"
class
=
"k-edit-field"
>
@Html.Kendo().DropDownListFor(model => model.CourseID).OptionLabel(
"Choose Course"
).HtmlAttributes(
new
{ style =
"width:400px"
}).DataTextField(
"CourseTitle"
).DataValueField(
"CourseID"
).ValuePrimitive(
true
).DataSource(ds => {
ds.Read(r =>
{
r.Action(
"Get_SimpleCourseList"
,
"Course"
);
});
})
</div>