Kendo UI for jQuery Grid日期未发布到服务器端

时间:2019-03-27 04:09:05

标签: jquery asp.net-mvc kendo-ui kendo-grid kendo-datepicker

我遇到Kendo网格弹出编辑器未将date数据发送到服务器端的问题。

请参见下面的代码:

JavaScript:

$(document).ready(function () {
        var serviceBaseUrl = "@Request.Url.ToString()",
            lostPropertyDataSource = new kendo.data.DataSource({
                transport: {
                    create: {
                        url: serviceBaseUrl + "/AddLostProperty",
                        type: "POST",
                        dataType: "json",
                    },
                    read: {
                        url: serviceBaseUrl + "/GetLostProperties",
                        type: "GET",
                        dataType: "json",
                        contentType: 'application/json; charset=utf-8',
                    },
                    update: {
                        url: serviceBaseUrl + "/UpdateLostProperty",
                        type: "POST",
                        dataType: "json"
                    },
                    destroy: {
                        url: serviceBaseUrl + "/DeleteLostProperty",
                        type: "DELETE",
                        dataType: "json"
                    },
                },
                requestEnd: onRequestEnd,
                pageSize: 20,
                schema: {
                    model: {
                        id: "PropertyId",
                        fields: {
                            //PropertyId: { type: "number", nullable: true },
                            PropertyName: { type: "string", editable: true, validation: { required: true } },
                            CategoryName: { type: "string", editable: true, validation: { required: true } },
                            PropertyDescription: { validation: { required: false } },
                            //Image: { validation: { required: false } },
                            FoundDate: { type: "date", format: '0:dd-MM-yyyy' },
                            FoundLocation: { editable: true, validation: { required: false } }
                        }
                    }
                },
            });


        $("#manageLostPropertiesGrid").kendoGrid({
            dataSource: lostPropertyDataSource,
            pageable: true,
            height: 550,
            toolbar: ["create"],
            columns: [
                //{ command: { text: "View Photo", click: showPhoto }, title: " ", width: "180px" },
                { field: "PropertyName", title: "Property Name", width: "150px" },
                { field: "CategoryName", title: "Category", editor: propertyCategoryList, width: "150px"},
                { field: "PropertyDescription", title: "Description", width: "200px" },
                { field: "FoundDate", type: "date", title: "Found Date", format: "dd/MM/yyyy", template: "#= kendo.toString(kendo.parseDate(FoundDate, 'dd-MM-yyyy'), 'dd/MM/yyyy') #",  width: "130px" },
                { field: "FoundLocation", title: "Found Location", width: "120px" },
                { command: ["edit", "destroy"], title: " ", width: "250px" }],
            editable: "popup"
        }).data("kendoGrid");

        function onRequestEnd(e) {
            if (e.type != "read") {
                e.sender.read();
            }
        }

        function propertyCategoryList(container, options) {
            $('<input name="' + options.field + '"/>')
                .appendTo(container)
                .kendoDropDownList({
                    autoBind: true,
                    dataTextField: "CategoryName",
                    dataValueField: "CategoryName",
                    valuePrimitive: false,
                    autoBind: true,
                    dataSource: {
                        transport: {
                            read: serviceBaseUrl + "/GetPropertyCategories",
                        }
                    }
                });
          }
    });

视图模型具有其他数据,但是即使在网格中输入了日期,日期也获得了null值。

enter image description here

从客户端发布的数据可以从浏览器中看到:

enter image description here

问题是如何从Kendo Grid将date发送到服务器端?

1 个答案:

答案 0 :(得分:0)

尝试以其他格式发布日期。您可以使用parameterMap更改格式:

class UserServiceListener
{
    private $token_storage;

    public function __construct(TokenStorageInterface $token_storage)
    {
        $this->token_storage = $token_storage;
    }

    public function prePersist(LifeCycleEventArgs $args)
    {
        $entity = $args->getEntity();

        if (!$entity instanceof UserService) {
           return;
        }

        $entity->setUser($this->token_storage->getToken()->getUser());
    }
}