Kendo Grid更新事件未启动

时间:2016-06-15 18:22:38

标签: c# asp.net kendo-ui

我正在使用MVC4 ASP.NET并尝试创建一个Kendo Grid,我可以在其中编辑内联数据。我正在使用Entity Framework连接到导入Visual Studio的本地数据库。我从这里跟踪了Kendos网页上的示例示例:http://demos.telerik.com/kendo-ui/grid/editing-inline这是我的视图

修改

在修改网格中的现有记录后单击“更新”按钮时,它不会在我的Controller UpdateAsset方法中启动。我还在Views update方法中添加了一个alert方法,但没有收到对话框。

文件代码:

@{
    ViewBag.Title = "Manage Assets";
}

<h2>ManageAssets</h2>

<div id="grid"></div>

<div>
    <form style="background-color:#E6E6FA">
        Switch:<input type="number" id="switch_txt" /><br />
        Port:<input type="text" id="port_txt" /><br />
        Name:<input type="text" id="name_txt" /><br />
        Connection:<input type="text" id="connection_txt" /><br />
        Interface:<input type="text" id="ifc_txt" /><br />
    </form>
</div>
<div>
    @*<input type="text" id="switchTxt" />*@ @*This is Justins original code (JOC) *@
    <button onclick="onSave()">Save</button><br />
</div>
<script>
    var selectedRow = {};
    var crudServiceBaseUrl = "/Asset";
    $(document).ready(function () {
        var dataSource = new kendo.data.DataSource({
            transport: {
                read: {
                    url: crudServiceBaseUrl + "/GetAssets",
                    dataType: "json",
                    contentType: "application/json"
                },
                update:  {

                    url: crudServiceBaseUrl + "/UpdateAsset",
                    dataType: "json",
                    type: "POST",
                    contentType: "application/json"
                },
                destroy: {
                    url: crudServiceBaseUrl + "/Destroy",
                    dataType: "jsonp"
                },
                parameterMap: function (options, operation) {
                    if (operation !== "read" && options.models) {
                        return { models: kendo.stringify(options.models) };
                    }
                }
            },
            pageSize: 20,
            autoSync: true,
            schema: {
                model: {
                    id: "Gid",
                    fields: {
                        Switch: { type: "number", editable: true, nullable: true, validation: { required: true, min: 1 } },
                        Port: { type: "string", editable: true, nullable: true },
                        Name: { type: "string" },
                        Connection: { type: "string" },
                        Interface: { type: "string" },
                        ConnectionUser: { type: "string" },
                        ConnectionDate: { type: "string" }
                    }
                }
            }
        });

        $("#grid").kendoGrid({
            dataSource: dataSource,
            pageable: true,
            height: 550,
            selectable: true,
            change: function () {
                selectedRow = {
                    mySwitch: this.dataItem(this.select()).Switch,
                    myPort: this.dataItem(this.select()).Port,
                    myName: this.dataItem(this.select()).Name,
                    myConnection: this.dataItem(this.select()).Connection,
                    myInterface: this.dataItem(this.select()).Interface
                };
                alert(selectedRow['mySwitch']);
            },
            columns: [
                { field: "Switch", title: "Switch", format: "{0:n}", width: "120px" },
                { field: "Port", title: "Port" },
                { field: "Name", title: "Name" },
                { field: "Connection", title: "Connection" },
                { field: "Interface", title: "Interface" },
                //{ command: ["edit", "destroy"], title: "&nbsp;", width: "250px" }],
                { command: [
                    {
                        name: "edit",
                        //click: function(e) {
                        //    alert("you just clicked edit");
                        //}
                    },
                    { name: "destroy"}
                ]}],
            editable: "inline"
        });
    });
    // when the Save button is pressed this function is called
    // the function creates the values for the table columns
    function onSave() {
        var myJSONObject = {
            //switchTxt is coming from the text field div
            asset_sw: $("#switch_txt").val(),
            asset_port: $("#port_txt").val(),
            asset_name: $("#name_txt").val(),
            asset_conn: $("#connection_txt").val(),
            asset_ifc: $("#ifc_txt").val()
        };
        //alert(myJSONObject);
        $.ajax({
            url: crudServiceBaseUrl + "/CreateAsset",
            dataType: "json",
            type: "POST",
            data: myJSONObject, // here we pass the json object that contains all of our data
            success: function (result) {
                if (result.success == true)
                {
                    alert(result.success);
                    alert('success');
                    $('#grid').data('kendoGrid').dataSource.read();
                    $('#grid').data('kendoGrid').refresh();
                }
                else {
                    alert(result.success);
                    alert('fail success');
                }

            },
            error: function (result) {
                alert(result);
                alert('fail')
            }
        });
    }
</script>

0 个答案:

没有答案
相关问题