【发布时间】:2016-05-26 03:18:42
【问题描述】:
工作计划视图模型
public class JobPlanViewModel : IMapFrom<JobPlan>, IJobPlan
{
...
[Display(Name = "Duration")]
public decimal Duration { get; set; }
...
}
我的剑道网格
@(Html.Kendo().Grid<JobPlanViewModel>()
...
.Editable(editable => editable.Mode(GridEditMode.PopUp)
.TemplateName("AdminJobPlanJobFormEditor")
.Window(w => { w.Title(""); })
.DisplayDeleteConfirmation(false))
...
.Update(update => update.Action("JobPlanGrid_Update", "JobPlan", new { area = "AdminJobPlan" }))
)
AdminJobPlanJobFormEditor.cshtml
@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>
我有一个使用弹出编辑模式的 Kendo MVC Grid,带有一个 cshtml 模板。
在该模板中,我有一个 Kendo MVC NumerictextboxFor duration 字段,我想将其默认值设置为 0.1,当用户单击“保存”时,该值应发布到服务器端操作 JobPlanGrid_Update即使他不编辑duration 字段
在UI中,一切似乎都很好,当弹出编辑窗口时,文本框中显示默认值0.1,最小值,步长值都可以,但是当我点击“保存”时,我发现@987654327如果我没有手动编辑duration,@ 发布的字段始终为 0。
我已经设置了 Grid 的 Datasource parameterMap。通过写console.log(),我发现它在做映射时(在网格向JobPlanGrid_Update发送请求之前),duration已经是0了,这出乎我的意料。
我做错了什么,我怎样才能实现我想要的?谢谢!
已编辑
我的全格是这样的:
@(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))
)
抱歉格式化,我不知道为什么 shift+tab 会清除所有缩进而不是清除一个制表符....
【问题讨论】:
-
发布您的整个网格。
标签: javascript c# asp.net-mvc kendo-asp.net-mvc