
I am having some odd issues with complex objects in my trial version of KendoUI complete for MVC.
I have a base entity class called Entity with the following 2 properties.
public Guid ObjectId { get; set; }
public DateTime CreatedOn { get; set; }
I then have 2 classes, Product and Category. Both inherit from Entity.
Product has a reference to a single category
public Category Category { get; set; }
My grid populates 100%.
The first issue I had was when displaying Category.CreatedOn. I was getting the JSON data instead of a date/time. Searching these forums found me an answer and I have it displaying correctly using the ClientTemplate method on the bound property.
When I make a change and post back the Product.CreatedOn is 100% and contains the value that it had originally in the read request. Category.CreatedOn is set back to 01/01/0001 00:00 which is invalid and causes my ModelState.IsValid check to fail.
This Category.CreatedOn value does however show in the grid correctly if I render the column after applying the ClientTemplate fix above.
If I set a new date in the grid for Category.CreatedOn, then this new value is persisted back to the server on update. The value is only lost if I don't alter it at all.
Am I making sense? Is there a fix for this?
I have been fiddling with DateTime types in the Grid since Thursday last week. Starting to feel real unproductive at the moment so some quick assistance would be appreciated.
TIA
Mike
12 Answers, 1 is accepted

I used
var errors = ModelState.Where(v => v.Value.Errors.Any());
to get a list of the errors on post back and found Category.CreatedOn property was failing validation.
The exception is "The value '/Date(1365085534000)/' is not valid for Created."
AttempedValue is "/Date(1365085534000)/" and culture is "en-ZA".
The CreatedOn value for the product its-self is correct and posting fine.
Why is one posting back fine and the other not? I am close to dumping the CreatedOn field for all entities but know I will just have to revisit this later when I introduce a date field and particularly a date field with the same name across objects and referenced objects.
Please assist. This is killing me now.

It is a critical problem I am having and consuming a lot of precious development time trying to figure out something that should just work.
Dropping $999 on the suite does not look so enticing anymore. I was prepared to put up with the faults as long as support was good. Oh well...
My client has already paid me the cash for the KendoUI full suite. 3 days left of the trial and was close to licensing. I am seriously reconsidering this position now.
/Off to trial other products.
Those issues sound a lot like a known issue caused by not including kendo.aspnetmvc.min.js in your application. Could this be the case? If that file is include the Kendo Grid will never send JavaScript dates as /Date()/. You can find more info here: http://docs.kendoui.com/getting-started/using-kendo-with/aspnet-mvc/introduction#using-kendo-ui-in-asp.net-mvc-3-application or if using ASP.NET MVC 4 http://docs.kendoui.com/getting-started/using-kendo-with/aspnet-mvc/introduction#using-kendo-ui-in-asp.net-mvc-4-application
Atanas Korchev
the Telerik team

It is the CreatedOn DateTime property for referenced properties that are being passed back in JSON format.
The CreatedOn property for the primary object is fine and passing back as a Date value.
I gave up on trying to work with my entities in your grid due to the long time it takes to get a response and am using ViewModels to flatten out my objects. So much extra work as the ViewModel's are really just my entity models flattened. Now I have to create ViewModels and map data back and forth between entity model and view model.

You will see in the grid there are two date columns.
"Created On" and "Shaft Created On".
If you alter any values EXCEPT for Shaft Created On, the ModelState will be invalid. I have made it throw an exception showing the AttemptedValue and the Key. It is a JSON value.
If however you set any date value for Shaft Created On, then it works fine and the ModelState will not be invalid.
I have 3 days left of my trial. Put some speed on this please.
I upgraded your project to the current official release 2013.1.319 and I couldn't reproduce the problem. All dates are submitted as strings. I have attached the updated project as well as a screenshot showing how the request looks like at my side.
On a side note I would like to remind you that the guaranteed trial response time is 72 hours (excluding weekends).
All the best,
Atanas Korchev
the Telerik team

I am unable to use the latest version as a trial. See attached screeny.
Would have gone a long way on my mental state to be able to have used the latest version as a trial and not have to go through this at all.
If the testapp now works as expected, I will go ahead and purchase the full version for $999 this afternoon.
What happens when you pick the first option (the one that says 2013.1.319)? Can't you download it from our web site?
All the best,Atanas Korchev
the Telerik team

public
abstract
class
ModelBase
{
[DisplayFormat(DataFormatString =
"{0:g}"
)]
[Editable(
false
)]
public
DateTime? ModifiedDate {
get
;
set
; }
}
public
class
Store : ModelBase
{
public
Store()
{
this
.Product =
new
HashSet<Product>();
this
.ProductCategory =
new
HashSet<ProductCategory>();
}
[Key]
public
int
Id {
get
;
set
; }
[Required]
public
string
Name {
get
;
set
; }
[ScriptIgnore]
public
ICollection<Product> Product {
get
;
set
; }
[ScriptIgnore]
public
ICollection<ProductCategory> ProductCategory {
get
;
set
; }
}
public
class
Product : ModelBase
{
[Key]
public
int
Id {
get
;
set
; }
[Required()]
public
int
StoreId {
get
;
set
; }
[ForeignKey(
"StoreId"
)]
public
Store Store {
get
;
set
; }
[Required()]
[MaxLength(50)]
public
string
Name {
get
;
set
; }
[Required()]
public
int
ProductCategoryId {
get
;
set
; }
[ForeignKey(
"ProductCategoryId"
)]
public
ProductCategory ProductCategory {
get
;
set
; }
}
bundles.Add(
new
ScriptBundle(
"~/bundles/jquery"
).Include(
"~/Scripts/kendo/2013.1.514/jquery-1.9.1.js"
));
bundles.Add(
new
ScriptBundle(
"~/bundles/kendo"
).Include(
"~/Scripts/modernizr-2.6.2.js"
,
"~/Scripts/kendo/2013.1.514/kendo.all.js"
,
"~/Scripts/kendo/2013.1.514/kendo.aspnetmvc.js"
,
"~/Scripts/cultures/kendo.culture.de-DE.js"
));
The dataSource schema does not support complex objects so the type of the "ModifiedDate" will not be known and it will not be converted to a JavaScript date and formatted. You should bind the Grid to a flattened view model which contains the date field in order to avoid the problem. An alternative would be to use the request Data function and format the date as expected by the model binder:
.Update(update => update.Action(
"action"
,
"controller"
).Data(
"convertDate"
))
function
convertDate(data) {
data[
"Store.ModifiedDate"
] = data.Store ? kendo.toString(data.Store.ModifiedDate,
"G"
) :
""
;
}
Daniel
Telerik

The data function solution worked for me. I found that you have to parse to date before call the tostring however...
.Update(update => update.Action("action", "controller").Data("convertDate"))
function convertDate(data) {
data["Store.ModifiedDate"] = data.Store ? kendo.toString(kendo.parseDate(data.Store.ModifiedDate, "G")) : "";
}​

Hi,
I've been struggling with the same problem for several hours. It's a little strange that Telerik support staff always suggest to flatten the viewmodel but it's working also without flattening. Only the issue with the date is really annoying.
For me, only the following solution worked:
<script>
function convertDate(data) {
data.PostalAddress.CreatedAt = data.PostalAddress ? kendo.toString(kendo.parseDate(data.PostalAddress.CreatedAt), "G") : "";
}
</script>
I'm using Kendo UI v.2015.2.805.545
Good luck
Sven