I am using VS2013 + ASP.NET MVC4 + Razor + Kendo Grid 2013.1.219
I am using sample from link
(Custom popup to foreign key)
After lot of work and fixes, its finally working except datetime column is not working. Its passing null dates in create. I have tried setting up below:
[DataType(DataType.DateTime)]
or custom template.
columns.Bound(p => p.Begin_dm).Title("Begin Date").Width(250).Format("{0:MM-dd-yyyy H:mm:ss}").EditorTemplateName("DateTime");
columns.Bound(p => p.End_dm).Title("End Date").Width(250).Format("{0:MM-dd-yyyy H:mm:ss}").EditorTemplateName("DateTime");
Here is my modal:
public class ProviderMaintenanceSMS
{
[ScaffoldColumn(false)]
public int? PMID { get; set; }
//[ScaffoldColumn(false)]
[Required]
[UIHint("GridForeignKey")]
public int ProviderID { get; set; }
[Required]
//[DataType(DataType.DateTime)]
public DateTime? Begin_dm { get; set; }
[Required]
//[DataType(DataType.DateTime)]
public DateTime? End_dm { get; set; }
//[ScaffoldColumn(false)]
//public DateTime Create_dm { get; set; }
}
View:
@using SystemDashboard;
@using Kendo.Mvc.UI;
@*model IEnumerable<SystemDashboard.ProviderMaintenanceSMS>*@
@(Html.Kendo().Grid<SystemDashboard.ProviderMaintenanceSMS>()
.Name("grid1")
.Columns(columns =>
{
columns.Bound(p => p.PMID).Hidden();
columns.ForeignKey(p => p.ProviderID, (List<ProviderLookup>)ViewData["providers"], "ProviderID", "ProviderName").Title("Provider").Width(150);
columns.Bound(p => p.Begin_dm).Title("Begin Date").Width(250).Format("{0:MM-dd-yyyy H:mm:ss}").EditorTemplateName("DateTime");
columns.Bound(p => p.End_dm).Title("End Date").Width(250).Format("{0:MM-dd-yyyy H:mm:ss}").EditorTemplateName("DateTime");
columns.Command(command => { command.Edit(); command.Destroy(); });
})
.ToolBar(toolbar => toolbar.Create())
.Editable(editable => editable.Mode(Kendo.Mvc.UI.GridEditMode.PopUp))
.DataSource(dataSource => dataSource
.Ajax()
.ServerOperation(false)
.Events(events => events.Error("error_handler"))
.Model(model =>
{
model.Id(p => p.PMID);
model.Field(p => p.PMID).Editable(false);
model.Field(p => p.ProviderID).DefaultValue(1);
})
.Create(update => update.Action("EditingSMS_Create", "PM"))
.Read(read => read.Action("EditingSMS_Read", "PM"))
.Update(update => update.Action("EditingSMS_Update", "PM"))
.Destroy(update => update.Action("EditingSMS_Destroy", "PM"))
)
)
Controller Create Method: (dates are always null here)
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult EditingSMS_Create([DataSourceRequest] DataSourceRequest request, ProviderMaintenanceSMS pm)
{
ProviderMaintenanceBusinessLayer BL = new ProviderMaintenanceBusinessLayer();
BL.CreateOrUpdatePMSMS(pm);
return Json(new[] { pm }.ToDataSourceResult(request, ModelState));
}
Thank you in advance. Looking forward to your reply.
Manish
I am using sample from link
(Custom popup to foreign key)
After lot of work and fixes, its finally working except datetime column is not working. Its passing null dates in create. I have tried setting up below:
[DataType(DataType.DateTime)]
or custom template.
columns.Bound(p => p.Begin_dm).Title("Begin Date").Width(250).Format("{0:MM-dd-yyyy H:mm:ss}").EditorTemplateName("DateTime");
columns.Bound(p => p.End_dm).Title("End Date").Width(250).Format("{0:MM-dd-yyyy H:mm:ss}").EditorTemplateName("DateTime");
Here is my modal:
public class ProviderMaintenanceSMS
{
[ScaffoldColumn(false)]
public int? PMID { get; set; }
//[ScaffoldColumn(false)]
[Required]
[UIHint("GridForeignKey")]
public int ProviderID { get; set; }
[Required]
//[DataType(DataType.DateTime)]
public DateTime? Begin_dm { get; set; }
[Required]
//[DataType(DataType.DateTime)]
public DateTime? End_dm { get; set; }
//[ScaffoldColumn(false)]
//public DateTime Create_dm { get; set; }
}
View:
@using SystemDashboard;
@using Kendo.Mvc.UI;
@*model IEnumerable<SystemDashboard.ProviderMaintenanceSMS>*@
@(Html.Kendo().Grid<SystemDashboard.ProviderMaintenanceSMS>()
.Name("grid1")
.Columns(columns =>
{
columns.Bound(p => p.PMID).Hidden();
columns.ForeignKey(p => p.ProviderID, (List<ProviderLookup>)ViewData["providers"], "ProviderID", "ProviderName").Title("Provider").Width(150);
columns.Bound(p => p.Begin_dm).Title("Begin Date").Width(250).Format("{0:MM-dd-yyyy H:mm:ss}").EditorTemplateName("DateTime");
columns.Bound(p => p.End_dm).Title("End Date").Width(250).Format("{0:MM-dd-yyyy H:mm:ss}").EditorTemplateName("DateTime");
columns.Command(command => { command.Edit(); command.Destroy(); });
})
.ToolBar(toolbar => toolbar.Create())
.Editable(editable => editable.Mode(Kendo.Mvc.UI.GridEditMode.PopUp))
.DataSource(dataSource => dataSource
.Ajax()
.ServerOperation(false)
.Events(events => events.Error("error_handler"))
.Model(model =>
{
model.Id(p => p.PMID);
model.Field(p => p.PMID).Editable(false);
model.Field(p => p.ProviderID).DefaultValue(1);
})
.Create(update => update.Action("EditingSMS_Create", "PM"))
.Read(read => read.Action("EditingSMS_Read", "PM"))
.Update(update => update.Action("EditingSMS_Update", "PM"))
.Destroy(update => update.Action("EditingSMS_Destroy", "PM"))
)
)
Controller Create Method: (dates are always null here)
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult EditingSMS_Create([DataSourceRequest] DataSourceRequest request, ProviderMaintenanceSMS pm)
{
ProviderMaintenanceBusinessLayer BL = new ProviderMaintenanceBusinessLayer();
BL.CreateOrUpdatePMSMS(pm);
return Json(new[] { pm }.ToDataSourceResult(request, ModelState));
}
Thank you in advance. Looking forward to your reply.
Manish