1

I'm using kendo ui to create a grid on my project. My problem is that i cannot pass a decimal value to my c# class model.

My class:

    public class BlocCoefficientSettings
{
    public int BlocCoefficientKey { get; set; }
    public string BlocName { get; set; }
    public string Category { get; set; }
    public string MinMaxFloor { get; set; }
    public int Rooms { get; set; }
    public decimal CoefficientValue { get; set; }
    public int GroupNumber { get; set; }
}

And this is my code that renders the grid

@section Scripts{
<script>


            function grid_init() {
                var dataSearch = {
                    classifierSearchKey: document.getElementById('classifierSearchKey').value
                }

                if (!dataSearch.classifierSearchKey == "") {

                    var dataSource = new kendo.data.DataSource({
                        transport: {
                            read: {
                                url: "/BlocCoefficientsSettings?handler=Json",
                                dataType: "json",
                                data: dataSearch
                            },
                            update: {
                                url: "/Common/UpdateBlocCoefficientsSettings",
                                type: "POST",
                                dataType: "json"
                            }
                        },
                        batch: true,
                        sort: [{ field: "groupNumber", dir: "asc" }, { field: "rooms", dir: "asc" }],
                        schema: {
                            data: "results",
                            total: "total",
                            model: {
                                id: "blocCoefficientKey",
                                fields: {
                                    blocName: { editable: false },
                                    rooms: { editable: false, type: "number" },
                                    minMaxFloor: { editable: false },
                                    coefficientValue: { editable: true, type: "number", nullable: true }
                                }
                            },
                        },
                        page: 1,
                        serverPaging: false,
                        group: { field: "category" }
                    });
                    $("#grid").empty();

                    $("#grid").kendoGrid({

                        dataSource: dataSource,
                        editable: true,
                        height: 700,
                        sortable: true,
                        groupable: false,
                        toolbar: [{ name: "save", text: "Сохранить" }],

                        columns: [

                            { field: "blocName", title: "Блок", width: "200px" },
                            { field: "minMaxFloor", title: "Этаж", width: "70px" },
                            { field: "rooms", title: "Комнат", width: "50px" },
                            { field: "coefficientValue", title: "Коэффициент этажности", width: "50px" },
                            { field: "category", hidden: true, groupHeaderTemplate: "Категория недвижимости: #= value #" }
                        ]
                    });
                }
                else {
                    alert("Выберите застройку!");
                }
            }

            $("#btnSearch").click(function () {
                grid_init();
            });

</script>

All works fine when put a whole number in the coefficientValue field. The whole number is passed to my model. But when i put a decimal number to my model is passed 0(In my example the value should be 1.5 for models[1])

enter image description here

Picture

How can i pass a decimal number?

1 Answers1

0

I'm not sure how you are prompting for a number here, but be careful with culture settings. JSON does not support comma decimal separation, only point. Thus, you the JSON being posted has to show the value as 1.5, not 1,5 or it isn't going to parse correctly on server side.

Daniel Lorenz
  • 4,178
  • 1
  • 32
  • 39