Difference Between Curly Braces and Parentheses

4 posts, 0 answers
  1. Ken Lewis
    Ken Lewis avatar
    28 posts
    Member since:
    Sep 2009

    Posted 06 Mar 2013 Link to this post

    This question arose while configuring grids, but it's a more general question, which is why I'm posting it here. Here's the situation.

    I was trying to set up a grid hierarchy using server binding and couldn't get the subgrid data to show up. Then I switched to using curly braces, @{ ... }, to surround the grid instead of parentheses, @( ... ), and it worked beautifully. So, here's the question: What is the difference between the syntax for the two grids below? (They both result in the same output.)

    Grid with Parentheses:
    @(Html.Kendo().Grid(Model)   
        .Name("JobCodesGrid")
        .Columns(columns =>
        {
            columns.Bound(m => m.RegionID).Title("Region");
            columns.Bound(m => m.JobCodeText).Title("Job Code");
        })
    )

    Grid with Curly Braces:
    @{Html.Kendo().Grid(Model)   
        .Name("JobCodesGridBraced")
        .Columns(columns =>
        {
            columns.Bound(m => m.RegionID).Title("Region");
            columns.Bound(m => m.JobCodeText).Title("Job Code");
        })
        .Render();
    }

    Why is it better, if that's true, to use curly braces for a hierarchy scenario (with subgrid in DetailTemplate) than parentheses?

    Thanks for any help!

    Ken

  2. Dimiter Madjarov
    Admin
    Dimiter Madjarov avatar
    2159 posts

    Posted 08 Mar 2013 Link to this post

    Hi Ken,

    The parenthesis define an explicit expression and the curly brackets define a regular C# code block. The difference is that the explicit expression submits it's output directly as a part of the HTML mark up and the code block doesn't. This is why when the second approach is used, the Render method should be called in order to render the component's mark up. 

    Regarding your second question, both approaches could be used in a hierarchy scenario. You could find an example, which is implemented using the parenthesis syntax in the server hierarchy MVC demo.
      

    Kind regards,
    Dimiter Madjarov
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Ken Lewis
    Ken Lewis avatar
    28 posts
    Member since:
    Sep 2009

    Posted 08 Mar 2013 Link to this post

    Dimiter,

    Thanks for the great explanation.

    Regarding the server hierarchy demo, is there one? I've looked and I only see an Ajax example. Can you post a link?

    Thanks,

    Ken
  5. Dimiter Madjarov
    Admin
    Dimiter Madjarov avatar
    2159 posts

    Posted 11 Mar 2013 Link to this post

    Hi Ken,

    You could find the demo about server hierarchy in the examples solution, which is included in Kendo UI for ASP.NET MVC. It is in the \wrappers\aspnetmvc\Examples folder.
     

    Greetings,
    Dimiter Madjarov
    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
UI for ASP.NET MVC is VS 2017 Ready