我有一个计划:剑道PanelBar剑道调度EditTemplate
@(Html.Kendo().Scheduler<HTServices.Models.TaskViewModel>()
.Name("scheduler")
.Date(DateTime.Now)
.StartTime(new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 7, 00, 00))
.Height(600)
.Editable(edit =>
{
edit.TemplateName("ScheduleItemTemplate");
edit.Create(false);
edit.Destroy(false);
})
.Views(views =>
{
views.DayView();
views.WeekView(workWeekView => workWeekView.Selected(true));
views.MonthView();
views.AgendaView();
})
.DataSource(d => d
.Model(m =>
{
m.Id(f => f.TaskID);
m.Field(f => f.Title).DefaultValue("No title");
m.Field(f => f.OwnerID).DefaultValue(1);
m.Field(f => f.Title).DefaultValue("No title");
m.RecurrenceId(f => f.RecurrenceID);
})
.Read("Read", "Scheduler")
.Create("Create", "Scheduler")
.Destroy("Destroy", "Scheduler")
.Update("Update", "Scheduler")
)
)
它与我的自定义模板加载很大。
@model HTServices.Models.TaskViewModel
@{
//required in order to render validation attributes
ViewContext.FormContext = new FormContext();
}
@functions{
}
<div class="k-edit-label">
@(Html.LabelFor(model => model.Client))
</div>
<div data-container-for="client" class="k-edit-field">
@(Html.TextBoxFor(model => model.Client, new { style = "width:100%;", @readonly = "readonly", @class = "k-textbox col-lg-12", data_bind = "text: client" }))
</div>
<div class="k-edit-label">
@(Html.LabelFor(model => model.Address))
</div>
<div data-container-for="address" class="k-edit-field">
@(Html.TextBoxFor(model => model.Address, new { style = "width:100%;", @readonly = "readonly", @class = "k-textbox", data_bind = "text: address" }))
</div>
<div class="k-edit-label">
@(Html.LabelFor(model => model.Start))
</div>
<div data-container-for="start" class="k-edit-field">
@(Html.TextBoxFor(model => model.Start, new { style = "width:100%;", @class = "k-textbox", @readonly = "readonly", data_bind = "value: start" }))
</div>
<div class="k-edit-label">
@(Html.LabelFor(model => model.End))
</div>
<div data-container-for="end" class="k-edit-field">
@(Html.TextBoxFor(model => model.End, new { style = "width:100%;", @class = "k-textbox", @readonly = "readonly", data_bind = "value: end" }))
</div>
<div class="k-edit-label">
@(Html.LabelFor(model => model.IsAllDay))
</div>
<div data-container-for="isAllDay" class="k-edit-field">
@(Html.DisplayFor(model => model.IsAllDay, new { @class = "k-checkbox", @readonly = "readonly", data_bind = "value: isAllDay" }))
</div>
<div class="k-edit-label">
@(Html.LabelFor(model => model.Description))
</div>
<div data-container-for="description" class="k-edit-field">
@(Html.TextAreaFor(model => model.Description, new { @class = "k-textbox", @readonly = "readonly", data_bind = "value: description" }))
</div>
<div class="k-edit-label">
@(Html.LabelFor(model => model.DutyID))
</div>
<div data-container-for="duties" data-task-id="@Model.TaskID" class="k-edit-field">
</div>
@{
ViewContext.FormContext = null;
}
,然后我添加PanelBar与绑定到一个分层模型......是的,它应该是可能的:
看到link for hierarchical model binding:
(Html.Kendo().PanelBar()
.Name("dutyPanel")
.ExpandMode(PanelBarExpandMode.Single)
.BindTo(Model.Duties, mappings =>
{
mappings.For<PanelGroup>(binding => binding //define first level of panelbar
.ItemDataBound((item, dutygrp) => //define mapping between panelbar item properties and the model properties
{
item.Text = dutygrp.Text;
item.ImageUrl = dutygrp.ImageUrl;
})
.Children(dutygrp => dutygrp.Items)); //define which property of the model contains the children
mappings.For<PanelGroupItem>(binding => binding
.ItemDataBound((item, duty) =>
{
item.Text = duty.Text;
item.ImageUrl = duty.ImageUrl;
}));
})
但后来,当我运行应用程序,并导航到页面,在控制器的索引操作甚至发生火灾之前,我得到:
System.NullReferenceException未被用户代码处理
HResult = -2147467261
Message =未将对象引用设置为对象的实例。
源= Kendo.Mvc
线:
.BindTo(Model.Duties, mappings =>
可见职责,模型构件,为空。是的,不要开玩笑吧...控制器的动作还没有被打到。
我想这是一个错误?