我在网格中使用数字文本框。但是数据不绑定。为什么它不起作用?

I'm using numerictextbox in grid. But the data does not bind. Why it is not working?

我想将 numerictextbox 放入我的 kendo 网格中。所以,我决定使用编辑器模板。这是有效的,因为当我 运行 它时,数字文本框出现了。但是,我插入一些数字后,数字会显示,但如果我点击任何地方,数字就会消失,因为我没有插入任何东西。

这是我在索引中的代码。

@(Html.Kendo().Grid((IEnumerable<DDLnetcore.Models.Product>)ViewBag.Product)
                                .Name("grid")
                                .Columns(columns =>
                                {
                                    columns.Bound(p => p.Name).Width(100);
                                    columns.Bound(p => p.Price).EditorTemplateName("Numeric");
                                    columns.Command(command => command.Destroy()).Width(150);
                                })
                                .ToolBar(toolBar =>
                                {
                                    toolBar.Create();
                                    toolBar.Save();
                                })
                                .Editable(editable => editable.Mode(GridEditMode.InCell))
                                .Pageable()
                                .Scrollable()
                                .Sortable()
                                .HtmlAttributes(new { style = "height:550px;" })
                                .DataSource(dataSource => dataSource
                                    .Ajax()
                                    .Batch(true)
                                    .PageSize(20)
                                    .ServerOperation(false)
                                    .Events(events => events
                                    .Error("errorHandler")
                                    )
                                    .Model(model =>
                                    {
                                        model.Id(p => p.Id);
                                        model.Field(p => p.Price);
                                    })
                                    .Read(read => read.Action("Index", "Products"))
                                    .Update(update => update.Action("Buatdata", "Products"))
                                    .Create(create => create.Action("Buatdata", "Products"))
                                    .Destroy(destroy => destroy.Action("Destroy", "Products"))
                               )
    )

这是我的编辑器模板代码

@model DDLnetcore.Models.Product

@(Html.Kendo().NumericTextBoxFor<decimal>(m => m.Price)
                .Format("c")
                .Min(0)
                .Max(100)
)

索引中的代码已经读取了我的编辑器模板代码,因为显示了数字文本框。但数据不受约束。我的代码有什么问题吗?

我已经找到问题了。问题出在我的编辑器模板中。有同样问题的朋友,尝试在编辑器模板中更改此代码。

@model decimal

@(Html.Kendo().NumericTextBoxFor<decimal>(m => m)
                            .Format("c")
                            .Min(0)
                            .Max(100)
)

谢谢。