Reputation: 35
I want to populate a dropdownlist from a action method. when i load the view for the first time it work great, but when I reload the view it doesn't call the action again.
The problem is if I delete an item from the database, the dropdownlist doesn't refresh the results.
My View:
@(Html.Kendo().DropDownListFor(model => model.IdSistema)
.Name("ddlSystems")
.OptionLabel("<.. Select an item ..>")
.DataTextField("DescSys")
.DataValueField("Id")
.HtmlAttributes(new { Style = "Width:243px;" })
.DataSource(source =>
{
source.Read(read =>
{
read.Action("GetAllSystems", "Systems");
})
.ServerFiltering(true);
})
.SelectedIndex(0)
)
My controller:
public JsonResult GetAllSystems([DataSourceRequest] DataSourceRequest request)
{
var items = (from row in _SystemService.GetAll()
orderby row.DescSys
select new { row.Id, row.DescSys });
return Json(items, JsonRequestBehavior.AllowGet);
}
Thanks for helping me.
Upvotes: 1
Views: 2310
Reputation: 1193
@(Html.Kendo().DropDownListFor(model => model.IdSistema)
.Name("ddlSystems")
.OptionLabel("<.. Select an item ..>")
.DataTextField("DescSys")
.DataValueField("Id")
.HtmlAttributes(new { Style = "Width:243px;" })
.DataSource(source =>
{
source.Read(read =>
{
read.Action("GetAllSystems", "Systems");
read.Type(HttpVerbs.Post);
})
.ServerFiltering(true);
})
.SelectedIndex(0)
)
****************************************Controller********************
[HttpPost]
public JsonResult GetAllSystems([DataSourceRequest] DataSourceRequest request)
{
var items = (from row in _SystemService.GetAll()
orderby row.DescSys
select new { row.Id, row.DescSys });
return Json(items, JsonRequestBehavior.AllowGet);
}
Upvotes: 3