How to resolve issues with CRUD Operations in an ASP.NET MVC Kendo UI Grid

寵の児 提交于 2019-12-06 13:23:26

try to change this one on your view

.Read(read => read.Action("GetAllUsers", "Admin"))
.Update(update => update.Action("UpdateUser", "Admin"))
.Destroy(update => update.Action("DeleteUser", "Admin"))

to this one

.Read("GetAllUsers", "Admin")
.Update("UpdateUser", "Admin")
.Destroy("DeleteUser", "Admin")

and on your controller

public ActionResult UpdateUser([DataSourceRequest] DataSourceRequest request, UserInfo user) ...
public ActionResult DeleteUser([DataSourceRequest] DataSourceRequest request, UserInfo user) ...

to this one

public ActionResult UpdateUser([Bind(Prefix = "models")]IEnumerable<UserInfo> updatedItems)
{
foreach (var updatedItem in updatedItems.AsNotNull())
            {
                   //--your code---//
            }
}

public ActionResult DeleteUser([Bind(Prefix = "models")]IEnumerable<UserInfo> deletedItems)
{
foreach (var deletedItem in deletedItems.AsNotNull())
            {
                   //--your code---//
            }
}

The order of the Kendo javascript files are important for this to work properly.

Make sure that this reference is that last one that loads, after the other kendo scripts.

  <script src="/Scripts/kendo.aspnetmvc.min.js"></script>

Please see here for further information:

http://docs.kendoui.com/getting-started/using-kendo-with/aspnet-mvc/helpers/grid/troubleshooting

loxdog

The issue was related to the fact the grid was performing a GET and not a POST, but unfortunately the solution provided by hutchonoid didn't work. That changed all the grid actions to posts, including the GET action. However, it did get me looking in the right place for the solution.

An answer given to another question actually resolved the issue. To get my grid working, I explicitly defined what action the grid actions should be:

.Read(read => read.Action("GetAllUsers", "Admin").Type(HttpVerbs.Get))
.Update(update => update.Action("UpdateUser", "Admin").Type(HttpVerbs.Post))
.Destroy(update => update.Action("DeleteUser", "Admin").Type(HttpVerbs.Post))

I'm still not entirely sure why the Telerik demo works without defining the type of the action, but I'm guessing it is related to the scripts. Perhaps the version of jQuery I'm using?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!