Hi I am trying to use AJAX to edit a grid.
First I made model (BPViewModel):
public DateTime Day { get; set; }
The Repository:
public static IList<BPViewModel> All()
{
IList<BPViewModel> result = (IList<BPViewModel>)HttpContext.Current.Session["BloodPressures"];
// string id = "2222222222";
// id = Session["PHN"].ToString();
if (result == null)
{
HttpContext.Current.Session["BloodPressures"] = result =
(from bloodpressure in new DALDataContext().BloodPressures
select new BPViewModel
{
.......
Day = bloodpressure.Day
}).ToList();
}
return result;
}
In the controller I get the data using"
public ActionResult BloodPressure_Read([DataSourceRequest] DataSourceRequest request)
{
return Json(BPRepository.All().ToDataSourceResult(request));
}
In the view:
@(Html.Kendo().Grid<BPViewModel>()
.Name("Grid")
.Columns(columns =>
columns.Bound(p => p.Day).Format("{0:d}");
The date is displayed as 1/1/2012; however when I edit it (using Ajax) it shows as Sun Jan 1 00:00:00 PST 2012!! When I try to update the row, I get "Day is invalid Date.
I tried to use bloodpressure.Day.ToShortDateString(), it did not work.
Any idea how I can convert the date to yyyy,mm,dd? Thanks in advance.
For reference, here is some reading material on MSDN for date time formatting: http://msdn.microsoft.com/en-us/library/8kb3ddd4
That said have you tried something as simple as the following:
yourdate.ToString("yyyy-MM-dd");