簡體   English   中英

從Kendo網格內的Kendo Color Picker更新服務器

[英]Updating server from Kendo Color picker inside kendo grid

問題

所以我目前正在嘗試在Kendo網格中實現一個顏色選擇器,希望它將選擇的顏色發送到我的Sql Table中。 不幸的是,似乎並沒有達到Update控制器。 我是Kendo UI的新手,因此可能會顯示一些非常愚蠢的錯誤。

問題

我想我的主要問題是:單擊網格上的更新后,如何調用更新方法。 本質上,顏色選擇器和編輯命令以漂亮的方式顯示。 我只是想知道如何確定單擊“更新”時是否正在調用該方法,因為它沒有到達我的控制器。 隨意詢問您是否需要查看更多代碼或截屏。

Config.cshtml(網格)

@model IEnumerable<STZN.Models.AGCData.ErrorCode>

@{
    ViewBag.Title = "Config";
}


@section HeadContent{
<script src="~/Scripts/common.js"></script>
    <script>

        $(document).ready(function () {
           $("#grid").kendoGrid({
               editable: "inline",
               selectable: "row",
               dataSource: {
                   schema: {
                       model: {
                           id: "error_code",
                           fields: {
                               color: { type: 'string' }
                           }
                       }
                   },

                   transport: {

                       read: {
                           type: "POST",
                           dataType: "json",
                           url: "@Url.Action("ErrorCodes")"
                       },
                       update: {
                           type: "POST" ,
                           dataType: "json",
                           url: "@Url.Action("UpdateErrorCodes")",

                       }
                   }
               },

               columns: [
                   { command : [ "edit" ] },
                   {
                       field: "error_code", title: "Error Code",

                   },
                   {
                       field: "error_description", title: "Error Description"
                   },
                   {
                       field: "color",
                       width: 150,
                       title: "Color",
                       template: function (dataItem) {
                           return "<div style = 'background-color: " + dataItem.color + ";'&nbsp;</div>"
                       },
                       editor: function (container, options) {
                           var input = $("<input/>");
                           input.attr("color",options.field);
                           input.appendTo(container);
                           input.kendoColorPicker({
                               value: options.model.color,
                               buttons: false
                           })
                       },

                   }

               ]
           });
       });


    </script>
}

更新控制器

public JsonResult UpdateErrorCodes(ErrorCode model)
        {


            using (var db = new AgcDBEntities())
            {
                db.Entry(model).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();

                db.Configuration.ProxyCreationEnabled = false;
                var data = db.ErrorCodes.Where(d => d.error_code == model.error_code).Select(x => new
                {
                    error_code = x.error_code,
                    description = x.error_description,
                    color = x.color,
                });

                return new JsonResult()
                {
                    JsonRequestBehavior = System.Web.Mvc.JsonRequestBehavior.AllowGet,
                };
            }
        }

實際上,我通過在“顏色”字段中的編輯器功能中添加了一個附加的輸入屬性來解決了我的問題。 看起來像這樣:

input.attr("data-bind","value:" + options.field);

目前仍然存在一些問題(與修訂/服務器更新無關),但就服務器的更新而言,它按預期工作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM