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

Using Html.RenderAction in a Toolbar Template in MVC

1 Answer 226 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ian
Top achievements
Rank 2
Ian asked on 21 Aug 2013, 06:21 PM
In the folowing I am trying to render the output of an action to the grid using MVC 4:

     .ToolBar(t=>t.Template(@<text>
             @Html.RenderAction("DisplayAccountDropDown", "ClientAccountState");
             <button class="k-button" id="clearFilter">Clear</button>
             <a class="k-button" href="@Url.Action("Export", "Holdings")" >Export</a>
          </text>))


But the Html.RenderAction doesn't have a return value to render so throws an error. Is there a way to get the output of the action into the toolbar? I am converting an app to use Kendo so would rather not have to change the controller if possible.

1 Answer, 1 is accepted

Sort by
0
Accepted
Rosen
Telerik team
answered on 23 Aug 2013, 11:57 AM
Hello Ian,

In order to render the action inline in the Toolbar template you will need to render the widget by call to its Render method.

@{Html.Kendo().Grid<Kendo.Mvc.Examples.Models.ClientProductViewModel>()
    .Name("grid")   
    .ToolBar(toolbar =>
    {
        toolbar.Template(@<text>
            @{Html.RenderAction("Test", "Grid");}
             <button class="k-button" id="clearFilter">Clear</button>
             <a class="k-button" href="@Url.Action("Export", "Holdings")" >Export</a>
        </text>);
    }) 
    .DataSource(dataSource => dataSource
        .Ajax()
        //...
    ).Render();
}

Note that the Grid initialization is enclosed into @{ } block.Regards,
Rosen
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Grid
Asked by
Ian
Top achievements
Rank 2
Answers by
Rosen
Telerik team
Share this question
or