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

Difference Between Curly Braces and Parentheses

3 Answers 404 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Ken Lewis
Top achievements
Rank 1
Ken Lewis asked on 07 Mar 2013, 02:45 AM
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

3 Answers, 1 is accepted

Sort by
0
Dimiter Madjarov
Telerik team
answered on 08 Mar 2013, 10:27 AM
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!
0
Ken Lewis
Top achievements
Rank 1
answered on 08 Mar 2013, 02:35 PM
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
0
Dimiter Madjarov
Telerik team
answered on 11 Mar 2013, 03:23 PM
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!
Tags
General Discussions
Asked by
Ken Lewis
Top achievements
Rank 1
Answers by
Dimiter Madjarov
Telerik team
Ken Lewis
Top achievements
Rank 1
Share this question
or