Hello,
Can someone please help.
I'm trying to do a simple Inline edit grid which has a datetime field but when clicking update the datetime field which is passed through to the controller has null. It's actually replicated in the example which Progress supply.
How do I get a valid date through to the controller? surely this is quite a big issue? is it a locale problem?
.chtml
}
<div class="row">
<div class="col-xs-18 col-md-12">
@(Html.Kendo().Grid<Sample.Models.OrderViewModel>()
.Name("grid")
.Columns(columns =>
{
columns.Bound(p => p.Freight);
columns.Bound(p => p.OrderDate);
columns.Bound(p => p.ShipName);
columns.Bound(p => p.ShipCity);
columns.Command(command => { command.Edit(); command.Destroy(); }).Width(160);
})
.Pageable()
.Sortable()
.Editable(editable => editable.Mode(GridEditMode.InLine))
.Scrollable()
.Filterable()
.HtmlAttributes(new { style = "height:550px;" })
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(20)
.Batch(true)
.Model(model => model.Id(p => p.OrderID))
.Read(read => read.Action("Orders_Read", "Grid"))
.Update(update => update.Action("Orders_Update", "Grid"))
)
)
</div>
</div>
GridController.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Kendo.Mvc.UI;
using Sample.Models;
using Kendo.Mvc.Extensions;
namespace Sample.Controllers
{
public class GridController : Controller
{
public ActionResult Orders_Read([DataSourceRequest]DataSourceRequest request)
{
var result = Enumerable.Range(1, 50).Select(i => new OrderViewModel
{
OrderID = i,
Freight = i * 10,
OrderDate = new DateTime(2016, 9, 15).AddDays(i % 7),
ShipName = "ShipName " + i,
ShipCity = "ShipCity " + i
});
var dsResult = result.ToDataSourceResult(request);
return Json(dsResult);
}
[AcceptVerbs("Post")]
public ActionResult Orders_Update([DataSourceRequest]DataSourceRequest request, [Bind(Prefix = "models")]IEnumerable<OrderViewModel> products)
{
//products.OrderDate is null even though I've selected a date on the edit datepicker.
return Json(products.ToDataSourceResult(request));
}
}
}