I hope this is an easy fix. I have a DropDownList in my Grid which seems to be working fine except the selected value is not being returned to the Controller Action. For example, when I select a new value for "Type" below, it still shows the original value in the model in the Controller. See "<--" NOTES BELOW.
Thanks very much for the help.
*** MODEL ***
public class SelectValueViewModel
{
public int Id { get; set; }
public string Code { get; set; }
public string Description { get; set; }
[UIHint("SelectValuesTypeDropDown")]
public string Type { get; set; } // <-- TRYING TO UPDATE THIS VALUE WITH THE DROP DOWN.
public List<SelectListItem> CodeTypes { get; set; }
}
*** VIEW ***
@(Html.Kendo().Grid<CCMC.View_Models.SelectValueViewModel>()
.Name("SelectValuesGrid")
.Columns(c =>
{
c.Bound(m => m.Code).Width(100);
c.Bound(m => m.Description).Width(100);
c.Bound(m => m.Type).Width(100);
c.Command(command => { command.Edit(); }).Width(200);
c.Command(command => command.Destroy()).Width(150);
})
.ToolBar(toolbar => toolbar.Create())
.Editable(editable => editable.Mode(GridEditMode.InLine))
.Pageable()
.Sortable()
.Scrollable()
// .HtmlAttributes(new { style = "height:550px;" })
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(20)
.Model(model =>
{
model.Id(sv => sv.Type);
// model.Field(sv => sv.Id).Editable(false);
})
.Events(events => events.Error("error_handler"))
.Read(read => read.Action("Read", "SelectValues"))
.Update(update => update.Action("Edit", "SelectValues").Data("sendAntiForgery"))
.Destroy(destroy => destroy.Action("Delete", "SelectValues"))
)
)
*** EDIT TEMPLATE ***
@model CCMC.View_Models.SelectValueViewModel
@(Html.Kendo().DropDownListFor(m => m.Type)
.DataValueField("Value")
.DataTextField("Text")
.BindTo(Model.CodeTypes)
.BindTo((System.Collections.IEnumerable)ViewData["SelectValueTypes"])
)
*** CONTROLLER ***
[AcceptVerbs("Post")]
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<JsonResult> Edit([DataSourceRequest] DataSourceRequest request, SelectValueViewModel model)
{
model.Type // <--- THE VALUE IS NOT UPDATED HERE. STILL HAS THE ORIGINAL VALUE.
}