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

[Solved] Conditional DetailView with Server Binding

3 Answers 136 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Sam Rossetti
Top achievements
Rank 1
Sam Rossetti asked on 30 Apr 2012, 08:59 PM
I currently have a partial view that renders the Telerik MVC Grid. The model passed to the partial view contains a bool field that states whether or not the grid should contain a detail view.

The following code doesn't render the table but leaves the expand controls in place. Ideally I would like to hide the expand controls and the rendering of the template on the server side.

.DetailView(detailView => detailView.Template(
            @<text>
                @{ if (!Model.IsLowestLevel) {
                    @*render grid*@
                   }
                }
            </text>))

3 Answers, 1 is accepted

Sort by
0
Sam Rossetti
Top achievements
Rank 1
answered on 30 Apr 2012, 09:24 PM
Please disregard this post or just delete it.

0
Sam Rossetti
Top achievements
Rank 1
answered on 01 May 2012, 09:00 PM
I should of figured this out yesterday but the solution is to simply store my grid object in a variable and then check the bool in my model. Then I can modify my variable by adding the detail view on.
@{
    var mainGrid = Html.Telerik().Grid(Model.Rows)
    .Name("Grid_" + Model.Id);
 
    if (!Model.IsEditable) {
        mainGrid = mainGrid.DetailView(detailView => detailView.Template(
            @<text>
                @* Render Grid here *@
            </text>
        ));
    }
     
    mainGrid.Render();  
    }
0
Jesse
Top achievements
Rank 1
answered on 29 Jun 2012, 09:23 PM
Sam, thanks for sharing your solution.  This was exactly what I needed to do as well.
Tags
Grid
Asked by
Sam Rossetti
Top achievements
Rank 1
Answers by
Sam Rossetti
Top achievements
Rank 1
Jesse
Top achievements
Rank 1
Share this question
or