Kendo DropDownList问题在MVC上调用一个动作

时间:2014-05-28 16:50:26

标签: model-view-controller kendo-ui kendo-dropdown

我想从动作方法填充下拉列表。当我第一次加载视图它工作得很好,但是当我重新加载视图时它不会再次调用该操作。

问题是如果我从数据库中删除某个项目,则下拉列表不会刷新结果。

我的观点:

 @(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) 
                  ) 

@(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) )

我的控制器:

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);
}

感谢您的帮助。

1 个答案:

答案 0 :(得分:3)

@(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) 
                  ) 

<强> ******* ***控制器*****************

[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);
}
相关问题