This is a migrated thread and some comments may be shown as answers.

Configure AJAX data source to use proper javascript naming convention

6 Answers 255 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Greg
Top achievements
Rank 1
Greg asked on 26 Sep 2012, 11:08 PM
I am using Kendo UI Grid, using MVC helpers, and I see that JavaScript that gets generated assumes that JSON coming back from server will have property names with capitalized first letter (e.g. "Items" not "items"). Generated "schema" definition also uses names as they appear in C# class (i.e. first letter is capitalized). Also Data, Total and Error properties in the returned JSON (at the top level) are expected to start with capital letter.

Rest of my application uses proper javascript naming convention (i.e. camel case with lower first character).

Is there a way to configure MVC Helpers to output javascript that would conform to proper javascript naming convention? I have configured JSON serialization at the root of my application, and would rather not change my naming convention just to conform to Telerik's way.

6 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 27 Sep 2012, 08:11 AM
Hello,

There is no officially supported way to change that. What you see is the default behavior of the JavaScriptSerializer - it serializes .NET properties as they are. The naming convention for .NET properties is to start with capital letter - this is why they are serialized like this.

 On a side the JSON response  should be handled automatically by the grid. You should not be involved with using the properties of the response at all.

 If this is bothering you too much you could modify the source code. Renaming the properties of DataSourceResult and modifying  DataSourceSchema should be enough. However have in mind that we do not support such modifications.

All the best,
Atanas Korchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Greg
Top achievements
Rank 1
answered on 27 Sep 2012, 03:24 PM
How do I change DataSourceSchema?
Do you mean change source code of DataSourceSchema? If that's the case, where do I get source code for DataSourceSchema?

I also see that DataSourceSchema has public properties to change json property names (i.e. "Data", "Error", "Total"), how do I change those values when I create grid in .cshtml?

@(Html.Kendo().Grid<IssueListEntryViewModel>()
      .Name("NewIssues")
      .Columns(columns => {
          columns.Bound(p => p.Id).Title("Id");
      })
      .DataSource(ds => ds
        .Ajax()
        .Read(read => read.Url(Model.FooUrl))
      )
      )

0
Greg
Top achievements
Rank 1
answered on 27 Sep 2012, 03:25 PM
Also JavaScriptSerializer  is not a default JSON serializer in asp.net mvc 4.
0
Atanas Korchev
Telerik team
answered on 27 Sep 2012, 04:18 PM
Hello,

 Yes, you need to use the source code. It is shipped in the src directory of the distribution. You can't set the schema properties via fluent API because they are not exposed.

 The JSON serializer shipped with asp.net MVC 4 works in the exact same way as the JavaScriptSerializer - preserves the casing of the properties.

Regards,
Atanas Korchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Greg
Top achievements
Rank 1
answered on 01 Oct 2012, 05:38 PM
I can't find src folder. How do I get to it? I have downloaded both trial and complete packages, and neither has src folder.
0
Atanas Korchev
Telerik team
answered on 02 Oct 2012, 06:00 AM
Hi,

 You must download Kendo UI Complete for ASP.NET MVC commercial. It contains the src directory.

Greetings,
Atanas Korchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
General Discussions
Asked by
Greg
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Greg
Top achievements
Rank 1
Share this question
or