简体   繁体   English

自定义剑道网格工具栏按钮

[英]Custom kendo grid toolbar button

I have a Kendo Grid, in which I added a custom button in the toolbar.我有一个 Kendo Grid,我在其中的工具栏中添加了一个自定义按钮。 I have mapped a on click function to that button.我已经将点击 function 映射到该按钮。

 <div class="row">
        <div class="clearfix">
            @(Html.Kendo().Grid<ModelLayer.Models.TableNotificationModel>()
        .Name("successfullData")
        .ToolBar(e =>
        {
           e.Custom().Text("Save").HtmlAttributes(new { id = "customSaveButton", @class = "floatRight" });
        })
        .Pageable(pageable => pageable.Input(true).Numeric(false))
        .Scrollable()
        .Sortable()
        .Filterable()
        .ColumnMenu()
        .Groupable()
        .Columns(columns =>
        {
            columns.Bound(c => c.OPERATOR_OBJECTID).Title("ID").Hidden();
            columns.Bound(c => c.SETTLEMENT_CODE).Title("settlement code").Width("100px");
            columns.Bound(c => c.TECHNOLOGY_CODE).Title("tech code").Width("100px");
            columns.Bound(c => c.UPLOAD_SPEED_CLASS_CODE).Title("upload").Width("100px");
            columns.Bound(c => c.DOWNLOAD_SPEED_CLASS_CODE).Title("download").Width("100px");
            columns.Bound(c => c.DATA_CATEGORY_QOS_CODE).Title("data category").Width("100px");
            columns.Bound(c => c.SHAPE).Title("shape").Width("100px");
            columns.Bound(c => c.messageOut).Title("message").Width("100px");
        })
        .DataSource(dataSource => dataSource
            .Ajax()
            .PageSize(20)
            .Read(read => read.Action("Upload_Read", "Upload").Data("sendAdditional"))
            )
    )

        </div>
    </div>
<script>
    function sendAdditional() {
        var data = JSON.parse('@Html.Raw(Json.Serialize(Model?.TableNotificationModel))');

        return {
            model: data
        }
    }

$("#successfullData").on("click", "#customSaveButton", function () {
        var model = JSON.parse('@Html.Raw(Json.Serialize(Model?.TableNotificationModel))');
        

        $.ajax({
            method: "POST",
            url: '@Url.Action("SaveFile", "Upload")',
            data: {
                model: model,
                saveType: saveType
            } 
        })
    });
</script>

I added a function which send the model via an ajax call to my controller where I am returning a view.我添加了一个 function,它通过 ajax 调用将 model 发送到我的 Z594C103F2C6E04C3D8CZ 调用,其中 I0590ABA31 返回视图。 The problem is, the custom save button adds a # in the URL and I think it's because of that I cannot return the view of my action in the controller.问题是,自定义保存按钮在 URL 中添加了一个# ,我认为这是因为我无法返回 controller 中的操作视图。

public ActionResult SaveFile(List<TableNotificationModel> model)
        {
            //code shortened for brevity
            ViewBag.Message = String.Format(cmdMessage);
            return View(tModel);
        }

I am kind of stuck, I don't know how to proceed.我有点卡住了,我不知道如何继续。 Any suggestions?有什么建议么?

Check if your javascript function is identifying your button event by the ID: "customSaveButton".检查您的 javascript function 是否通过 ID:“customSaveButton”识别您的按钮事件。

For example:例如:

 $('#customSaveButton').on('click', function () {

    $.ajax({
        url: '/YourContreoller/SaveFile',
        type: 'POST',   
        dataType: 'json',
        data: $('#dataThatYouWantToSend').serialize(),
        success: function (sucess) {
            console.log("Success");
            document.location.href = '/'
        },
        error: function (xhr, textStatus, errorThrown) {
             console.log(textStatus);
        }

    });
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM