I have a Kendo DropDownlist as follow
<%= Html.Kendo().DropDownList()
.Name("AssignDisciplineId")
.DataSource(dataSource =>
{
dataSource.Read(read =>
{
read.Action("DisciplinesBySportAjax","Shared").Data("onDisciplinesBySportData");
});
})
.Events(events => events
.Change("onAssignDisciplineComboChanged")
)
.HtmlAttributes(new { style = "font-size:8pt;" })
%>
function onDisciplinesBySportData(e)
{
var sportId = $('#AssignSportsId').data('kendoDropDownList').value();
return { sportId: sportId }
}
[HttpPost]
public ActionResult DisciplinesBySportAjax(string sportId)
{
var sports = this._sportBL.GetDisciplinesBySport(sportId);
return new JsonResult
{
Data = new SelectList(sports, "Id", "Description")
};
}
But strangely enough, it does not execute DisciplinesBySportAjax in datasource.read and no data appears in the DropDownList. When changing to BindTo replacing DataSource, it works fine but I do not know how to dynamically reload its content in Jquery. Thanks.
Simply because a DropDownList doesn't use POST to get the data. Either remove [HttpPost]
or specify you want to use POST in the DataSource's Transport config.
I haven't checked if your method is done properly but that is the reason it's not being called at all.