Configure AJAX data source to use proper javascript naming convention

7 posts, 0 answers
  1. Greg
    Greg avatar
    5 posts
    Member since:
    Apr 2012

    Posted 26 Sep 2012 Link to this post

    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.
  2. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 27 Sep 2012 Link to this post

    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!
  3. Greg
    Greg avatar
    5 posts
    Member since:
    Apr 2012

    Posted 27 Sep 2012 Link to this post

    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))
          )
          )

  4. Greg
    Greg avatar
    5 posts
    Member since:
    Apr 2012

    Posted 27 Sep 2012 Link to this post

    Also JavaScriptSerializer  is not a default JSON serializer in asp.net mvc 4.
  5. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 27 Sep 2012 Link to this post

    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!
  6. Greg
    Greg avatar
    5 posts
    Member since:
    Apr 2012

    Posted 01 Oct 2012 Link to this post

    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.
  7. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 02 Oct 2012 Link to this post

    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!
Back to Top