Javascript Kendo MVC NumericTextBoxFor默认值不绑定到模型

Javascript Kendo MVC NumericTextBoxFor默认值不绑定到模型,javascript,c#,asp.net-mvc,kendo-asp.net-mvc,Javascript,C#,Asp.net Mvc,Kendo Asp.net Mvc,JobPlanViewModel public class JobPlanViewModel : IMapFrom<JobPlan>, IJobPlan { ... [Display(Name = "Duration")] public decimal Duration { get; set; } ... } 很抱歉设置了格式,我不知道为什么shift+tab会清除所有缩进,而不是清除一个选项卡……您还没有完全发布网格,所以我只能假设它使用Ajax绑定 这是因为剑道

JobPlanViewModel

public class JobPlanViewModel : IMapFrom<JobPlan>, IJobPlan
{
  ...
  [Display(Name = "Duration")]
  public decimal Duration { get; set; }
  ...
}

很抱歉设置了格式,我不知道为什么shift+tab会清除所有缩进,而不是清除一个选项卡……

您还没有完全发布网格,所以我只能假设它使用Ajax绑定

这是因为剑道网格的工作方式。我以前也有过类似的问题。例如,如果您尝试使用jquery在弹出式编辑器上更改输入的值,您将看到更改的值不会发布到控制器(该值不会在网格的数据源中更改),除非您在更改其值后显式触发输入的更改事件

不管怎样,您所做的并不是在网格中为属性设置默认值的正确方法。在网格的数据源中,应执行以下操作:

.DataSource(dataSource => dataSource
    .Ajax()
    .Model(m => m.Field(f => f.Duration).DefaultValue(0.1M))
    // other configurations...
)

发布你的整个网格。我已经在OP中添加了我的完整网格代码,我也会尝试你设置默认值的解决方案…会让你知道更新,谢谢!它就像一个符咒…我仍然需要在控件配置中设置.Value(),虽然对于UI显示默认值,但是这个方法确实设置了后面模型的默认值(因此模型发布到服务器端!),谢谢!
@model DefaultViewModel.JobPlanViewModel
@using Kendo.Mvc.UI
...
<div class="col-md-8 col-xs-12">
    @(Html.Kendo().NumericTextBoxFor(model => model.Duration)
    .Value(0.1m)
    .Step(0.1m)
    .Min(0.1m).Decimals(1).Format("N1")
    .HtmlAttributes(new { style = "width: 100%; padding: 0px;", required = "required" }))
    @Html.ValidationMessageFor(model => model.Duration)
</div>
@(Html.Kendo().Grid<JobPlanViewModel>()
    .Name("AdminJobPlanGrid")
    .AutoBind(false)
    .Columns(columns =>
    {
        columns.Bound(c => c.JobNo).Title(@Resources.Wording.JobNo).Width(80);
        columns.Bound(c => c.Description).Title(@Resources.Wording.Description);
        columns.Bound(c => c.Duration).Title(@Resources.Wording.DurationHours).ClientTemplate("#= kendo.format(\'{0:N1}\', Duration) #").Width(200);
        columns.Command(c => { c.Edit().UpdateText(Wording.Save).CancelText(Wording.Cancel).Text(Wording.Edit); c.Custom("Delete").Click("onAdminJobPlanJobDelete").Text(Wording.Delete);     }).Width(200);
    })
    .Pageable(page =>
    {
        page.Enabled(true);
        page.Messages(m =>
        {
            m.Display(Resources.Wording.GridDisplay);
            m.Empty(Resources.Wording.GridEmpty);
            m.Page(Resources.Wording.GridPage);
            m.Of(Resources.Wording.GridOf);
            m.ItemsPerPage(Resources.Wording.GridItemsPerPage);
            m.First(Resources.Wording.GridFirst);
            m.Previous(Resources.Wording.GridPrevious);
            m.Next(Resources.Wording.GridNext);
            m.Last(Resources.Wording.GridLast);
            m.Refresh(Resources.Wording.GridRefresh);
         });
    })
    .Scrollable(s => s.Height(80))
    .Sortable(s => s.Enabled(true))
    .Editable(editable => editable.Mode(GridEditMode.PopUp)
    .TemplateName("AdminJobPlanJobFormEditor")
    .Window(w => { w.Title(""); })
    .DisplayDeleteConfirmation(false))
    .DataSource(dataSource => dataSource.Ajax()
    .PageSize(20)
    .Sort(p => p.Add("JobNo").Ascending())
    .Model(model =>
    {
        model.Id(p => p.JobPlanJobID);
    })
    .Read(read => read.Action("JobPlanGrid_Read", "JobPlan", new { area = "AdminJobPlan" }))
    .Create(insert => insert.Action("JobPlanGrid_Update", "JobPlan", new { area = "AdminJobPlan" }))
    .Update(update => update.Action("JobPlanGrid_Update", "JobPlan", new { area = "AdminJobPlan" }))
    .Destroy(delete => delete.Action("JobPlanGrid_Update", "JobPlan", new { area = "AdminJobPlan" }))
    .ServerOperation(true))
)
.DataSource(dataSource => dataSource
    .Ajax()
    .Model(m => m.Field(f => f.Duration).DefaultValue(0.1M))
    // other configurations...
)