I’m new to Visual Studio and .net, so forgive me if I have some of the basics wrong.
This is what I wanna doe: fill content of a kendoui dropdownlist by using an ajax call. Now have I understood that it is preferred to use POST actions, but I cant get it to work.
Here’s my code within the view:
@(Html.Kendo().DropDownListFor(model => model.TypeId)
.DataTextField("Shortname")
.DataValueField("Id")
.DataSource(source => source.Read(read => read.Action("GetObjectTypes", "ObjectType")))
)
Here’s my controller code:
[HttpPost] // use post to prevent 'leeching'
public JsonResult GetObjectTypes()
{
var objectTypes = _objecttypeRepository.All;
return Json(objectTypes, JsonRequestBehavior.DenyGet);
}
The Ajax call doesn’t gets to the GetObjectTypes at all.
If I remove the [HttpPost] and the “JsonRequestBehavior.DenyGet” then this code works fine.
Many thanks in advance.
‘GET’ is actually the preferred method for retrieving resources (i.e. your dropdown list data), see HTTP protocol request methods. ‘POST’ is normally used to submit data and creating a new resource.
I haven’t done it myself, but if you really need to use ‘POST’ you may be able to specify it in the data source configuration, see kendo.data.DataSource’s transport.read.type.