C# Update命令未触发数据源的更新传输方法-Kendo Grid

C# Update命令未触发数据源的更新传输方法-Kendo Grid,c#,asp.net,asp.net-mvc-4,razor,kendo-ui,C#,Asp.net,Asp.net Mvc 4,Razor,Kendo Ui,嗨,我正在从用于绑定网格的存储过程返回一个数据表。没有从该数据表返回标识字段。在这个场景中,请帮助我触发“更新”、“销毁”和“创建” 这是我的控制器方法 public JsonResult Employee_Read([DataSourceRequest]DataSourceRequest request) { DataTable dt = new DataTable(); using (SqlConnection con = new

嗨,我正在从用于绑定网格的存储过程返回一个数据表。没有从该数据表返回标识字段。在这个场景中,请帮助我触发“更新”、“销毁”和“创建”

这是我的控制器方法

 public JsonResult Employee_Read([DataSourceRequest]DataSourceRequest request)
    {

            DataTable dt = new DataTable();
            using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["manualconn"].ConnectionString))
            {
                var command = new SqlCommand("usp_FetchUserDetails", con);
                command.CommandType = CommandType.StoredProcedure;

                    con.Open();
                    SqlDataAdapter da = new SqlDataAdapter(command);
                    da.Fill(dt);
                    System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
                    List<Dictionary<string, object>> rows = new List<Dictionary<string, object>>();
                    Dictionary<string, object> row;
                    foreach (DataRow dr in dt.Rows)
                    {
                        row = new Dictionary<string, object>();
                        foreach (DataColumn col in dt.Columns)
                        {
                            row.Add(col.ColumnName, dr[col]);
                        }
                        rows.Add(row);
                    }

                    return Json(rows, JsonRequestBehavior.AllowGet);


            }

   //     }

    }
这是我观点的一部分:

<script type="text/javascript">

var grid = $("#grid").data("kendoGrid");
var Employee = kendo.data.Model.define({
    id: "userDetailsId",
    fields: {
        "userDetailsId": { type: "number" },
        "Name": { type: "string" },
        "Department": { type: "string" },
        "Role": { type: "string" },
        "Email": { type: "string" },


    }
});

var dataSource = new kendo.data.DataSource({
    transport: {
        read: {
            url: '@Url.Action("Employee_Read", "UserSummary")',
            dataType: "json",
            cache: false,
            type: 'GET',
            //data: {
            //    test: $("#Names").val()
            //}
        },
        destroy: 
        //function (e) {
                  {
            url: '@Url.Action("Update_Details", "UserSummary")',
               type: "POST",
          //  dataType: "json",
            //data: {
            //    DAKy: $("#Names").val(),
            //    DIKy: $("#btntxt").val()
            //}
        },
        create: {
            url: '@Url.Action("Update_Details", "UserSummary")',
            type: "POST",
           // dataType: "json",
            //cache: false,
            //data: {
            //    AKy: $("#Names").val(),
            //    IKy: $("#btntxt").val()
            //}
        },
        update:         
        {
            url: '@Url.Action("Update_Details", "UserSummary")',
            type : "POST"
            //data: {
            //  AKy: $("#Names").val(),
            //  IKy: $("#btntxt").val()
            //       }
        }
              },
    error: function (e) {
        // handle error
        alert("Status: " + e.status + "\n" + e.errorThrown);
    },
    pageSize: 5,
                schema: {
                    model: {
                        id: "userDetailsId",
                        model: Employee
                    }
                }
            });

            $("#grid").kendoGrid({
                dataSource: dataSource,
                editable: "inline",
                //toolbar: ["create", "save"],
                autobind: true,
                pageable: true,
                columns: [
                    //{
                    //    field: "userDetailsId",
                    //    title: "userDetailsId",
                    //    width: "50px",

                    //},
                    {
                                field: "Name",
                                title: "Name",
                                width: "75px",
                                template: "<input id='Name' type='text' value='#: Name #' readonly> </input>",
                                editable:false,
                            },
                            {
                                field: "Department",
                                title: "Department",
                                width: "50px",
                                editor: ddlFetchDepartments


                            },
                            {
                                field: "Role",
                                title: "Role",
                                width: "50px",
                                editor: ddlFetchRoles

                            },
                            {
                                field: "Email",
                                title: "Email",
                                width: "100px",
                                template: "<input type='text' id='Email' size='35' value='#:Email#' readonly> </input>",
                                editable:false,
                            },

                             {
                                 command: ["edit", "destroy"], title: "&nbsp;", width: "75px"
                             },
                             { command: { text: "custom edit", click: showDetails },title: " ", width: "60px" }

                ],
            });



            function showDetails(e) {

                e.preventDefault();
                //debugger;
                var dataItem = this.dataItem($(e.currentTarget).closest("tr"));
                alert("View Details\n Name : " + dataItem.Name+"\nuserDetailsId : "+dataItem.userDetailsId); 
                @{

           //   ((MockProject.Controllers.UserSummaryController)this.ViewContext.Controller).Update_Details();

               }

            }

            function ddlFetchDepartments(container, options) {

                $('<input name="Departments" data-bind="value:' + options.field + '"/>')

                    .appendTo(container)

                    .kendoDropDownList({

                        dataTextField: "deptName",

                        dataValueField: "deptId",

                        autoBind: false,

                        dataSource: new kendo.data.DataSource({

                            transport: {

                                read: {

                                    url: '@Url.Action("FetchDepartments", "UserSummary")',
                                    type: 'GET',
                                    dataType: "json"

                                },
                                schema: {
                                    model: {
                                        id: "deptId",
                                        value: "deptName"
                                    }

                                }

                            }

                        })

                    });
            }
                function ddlFetchRoles(container, options) {

                    $('<input name="Roles" data-bind="value:' + options.field + '"/>')

                        .appendTo(container)

                        .kendoDropDownList({

                            dataTextField: "roleName",

                            dataValueField: "roleId",

                            autoBind: false,

                            dataSource: new kendo.data.DataSource({

                                transport: {

                                    read: {

                                        url: '@Url.Action("FetchRoles", "UserSummary")',
                                        type: 'GET',
                                        dataType: "json"

                                    },

                                    schema: {

                                        model: {

                                            id: "roleId",
                                            value: "roleName"

                                        }

                                    }
                             }
                            })
                        });
                }
            @*@{
                ((HomeController)this.ViewContext.Controller).Method1();
            }*@
    </script>
<br/>


&nbsp; <button type="button" id="btn_addUser" > &nbsp;Add User</button> 
&nbsp;  &nbsp;
<input type="submit" style="visibility:hidden" name="btn_save" class="k-button k-button-icontext" id="btn_save" value="Save" onclick="saveDataToDb()" />

<script type="text/javascript">

    function saveDataToDb() {

    }

    $('#btn_addUser').click(function () {

        document.getElementById('btn_save').style.visibility = "visible";
        $('#grid').data('kendoGrid').addRow();
    });

    function onEdit(e) {
        //Custom logic to default value
        var name = $("#AddSingleSuppliment").text();

        // If addition
        if (e.model.isNew()) {
            //set field
            e.model.set("Name", name); // Name: grid field to set
        }
    }

</script>


<script>
    $(document).ready(function () {
        $("#btn_addUser").kendoButton({
            spriteCssClass: "k-icon iconplus"
        });

    });
</script>


<style scoped>
    .k-button .k-image {
        height: 16px;
    }

    .demo-section {
        width: 500px;
    }

    .iconplus {
        background-image: url("../content/icons/plus.png");
        background-size: contain;
        /*background-position: 0 -64px;
        align-content: flex-start;
        align-self: auto;*/
    }
</style>

请尝试在架构中定义id。。。它被注释掉了,并且在执行更新、创建和销毁时是必需的。ID应该是数据库中的标识符。允许服务器在数据库中插入记录的文件。成功插入后,服务器应返回此值。该数据表不返回任何标识字段。那么,如果没有在数据库中标识它的唯一id,您将如何实现更新和删除?好的。谢谢你,布雷特。现在我已经将Id设置为“userDetailsId”。它仍然没有触发相应的更新删除事件。请看同样的。我已经更新了代码