Grid:
@(Html.Kendo().Grid<MVC.Models.Family>()
.Name(
"Grid"
)
.Columns(c =>
{
c.Bound(p => p.StreetId).Title(
"Street"
).ClientTemplate(
"#=GetStreet(data)#"
+
"<input type='hidden' name='StreetId' value='#=GetStreet(data)#'/>"
).Width(150);
c.Bound(p => p.FamilyName).Width(150).Title(
"Family"
);
c.Command(command => command.Destroy());
})
.Editable(editable => editable.Mode(GridEditMode.InCell).CreateAt(GridInsertRowPosition.Bottom))
.ToolBar(toolbar =>
{
toolbar.Template(
@<div>
<div
class
=
"c-tools"
><label>Street: </label>
@(Html.Kendo().DropDownList()
.Name(
"streets"
)
.HtmlAttributes(
new
{ style =
"width:150px"
})
.DataTextField(
"StreetName"
)
.DataValueField(
"Id"
)
.BindTo(Model.Streets)
)
</div>
<div
class
=
"c-tools"
>
<a
class
=
'k-button k-button-icontext k-grid-add'
href=
'#'
><span
class
=
'k-icon k-update'
></span>Add</a>
<a
class
=
'k-button k-button-icontext k-grid-save-changes'
href=
'#'
><span
class
=
'k-icon k-add'
></span>Save</a>
<a
class
=
'k-button k-button-icontext k-grid-cancel-changes'
href=
'#'
><span
class
=
'k-icon k-cancel'
></span>Cancel</a>
</div>
</div>
);
})
.DataSource(dataSource => dataSource
.Ajax()
.ServerOperation(
false
)
.Model(model => {
model.Id(p => p.Id);
model.Field(p => p.Id).Editable(
false
);
})
.Read(read => read.Action(
"Family_Read"
,
"Home"
)
)
.Update(
"Family_Update"
,
"Home"
)
.Create(
"Family_Create"
,
"Home"
)
)
)
js:
function
GetStreet(data) {
return
$(
"#streets"
).data(
"kendoDropDownList"
).value();
}
When I click on the add button then the StreetId is taken from the DropDonwlist, but if I start to edit it, then it becomes 0. Why?