0

我使用 kendo web 的开源版本,我当前的版本是 Kendo UI Web 我正在使用 kendo ui 和 asp.net mvc 4 我的 kendo 网格有这个 js 代码

<script>
   $(document).ready(function () {
       $("#grid").kendoGrid({
           dataSource: {
               type: "odata",
               serverSorting: true,
               serverFiltering: true,
               serverPaging: true,
               transport: {
                   read: {
                       url: "api/Usermanage",
                       dataType: "json",
                       contentType: "application/json"
                   },
                   create: {
                       url: "/api/Usermanage",
                       dataType: "json",
                       type: "POST"
                   },
                   update: {
                       url: function (UserModel) {
                           return "/api/articles/" + UserModel.ID
                       },
                       dataType: "json",
                       type: "PUT"
                   },
                   destroy: {
                   url: function (UserModel) {
                       return "/api/Usermanage/" + UserModel.ID
                   },
                   dataType: "json",
                   contentType: "application/json",
                   type: "DELETE"
                   },

                   update: {
                       url: function (UserModel) {
                           return "/api/Usermanage/" + UserModel.ID
                       },
                       dataType: "json",
                       type: "PUT"
                   },
                       parameterMap: function(options, operation) {
                           if (operation !== "read" && options.models) {
                               return {models: kendo.stringify(options.models)};
                           }
                       }


               },
               schema: {
                   data: function (response) {
                       if (response.value !== undefined)
                           return response.value;
                       else {
                           delete response["odata.metadata"];
                           return response;
                       }
                   },
                   total: function (response) {
                       return response['odata.count'];
                   },

                   model: {
                       fields: {
                           ID:"ID",
                           ID: { editable: false },
                           Name: { type: "string", editable: true, nullable: false, validation: { required: true } },
                           Roles: { type: "string" }
                       }
                   }
               }
           },
           height: 430,
           scrollable: {
               virtual: true
           },
           toolbar: ["create"],
           editable: "popup",
           sortable: true,
           columns: [
               { field: "Name", title: "UserName", width: 110 },
               { field: "Roles", title: "Role", width: 160 },
               { command: ["edit", "destroy"], title: " ", width: "160px" }
           ]
       });
   });
        </script>         
                       },

api控制器的方法是:

// DELETE api/usermanage/5
        public void Delete(int id)
        {
            var name = db.UserProfiles.Find(id);
            Membership.DeleteUser(name.UserName,true);
        }

但它不起作用,我做错了什么?

4

1 回答 1

-1

您所有的命令 url 都指向 url: "/api/Usermanage/"

这必须特定于您在控制器内部的操作,因此在这种情况下它应该是:

url: function (UserModel) {
   return "/api/Usermanage/Delete/" + UserModel.ID
},
于 2013-08-06T07:54:24.413 回答