Search code examples
c#asp.net-mvcteleriktelerik-gridtelerik-window

Can we have a grid inside Telerik Modal Window?


I am using ASP.NET MVC architecture.I have a telerik window on a button click, which works fine.The code is as follows-

    <% Html.Telerik().Window()
           .Name("Search")
           .Visible(false)
           .Title("Select Users")
           .Content(() => {%>                                           
    <% using (Html.BeginForm("GetUsers", "Administration", FormMethod.Post, 
        new{id ="users-form"}))
    {%>

    <p class="note">Mention the Users name to display information</p>                                                 
    <label for="username">Name:</label>                                                        
    <%= Html.TextBox("username") %>                           
    <div class="form-actions">
    <button type="button" class="bUsername">Search</button>
    </div>  
    <% } %>                                           
    <%})
    .Width(400)                                            
    .Modal(true)                                            
    .Render();%>

But when I try to add the telerik grid inside the content of telerik window it gives me error..code follows

    <%= Html.Telerik().Grid(Model)
    .Name("Grid")
    .Columns(columns =>
    {
        columns.Bound(o => o.OrderID).Width(100);
        columns.Bound(o => o.ContactName).Width(200);
        columns.Bound(o => o.ShipAddress);
        columns.Bound(o => o.OrderDate).Format("{0:MM/dd/yyyy}").Width(120);
    })
    .DataBinding(dataBinding => 
    {
        dataBinding.Server().Select("FirstLook", "Grid", new { ajax =
            ViewData["ajax"] });
        dataBinding.Ajax().Select("_FirstLook",
            "Grid").Enabled((bool)ViewData["ajax"]);
    })
    .Scrollable(scrolling => scrolling.Enabled((bool)ViewData["scrolling"]))
    .Sortable(sorting => sorting.Enabled((bool)ViewData["sorting"]))
    .Pageable(paging => paging.Enabled((bool)ViewData["paging"]))
    .Filterable(filtering => filtering.Enabled((bool)ViewData["filtering"]))
    .Groupable(grouping => grouping.Enabled((bool)ViewData["grouping"]))
    .Footer((bool)ViewData["showFooter"])
     %>

Error : .Content(() => {%> ----Delegate System.Func does not take 0 arguments.

So want to ask can we have grid inside modal window, if yes then how to implement it and if we cant than whats the alternative to it?


Solution

  • You shouldn't have any issues displaying a Grid in a Window. The following code, which uses the Customer entity from the Northwind database, worked just fine for me:

            <% Html.Telerik().Window()
           .Name("TelerikWindow")
           .Title("Grid in Window")
           .Draggable(true)
           .Modal(true)
           .Content(() =>
           { %>
        <%= Html.Telerik().Grid(Model)
                .Name("TelerikGrid")
                .Columns(columns =>
                {
                    columns.Bound(c => c.CustomerID);
                    columns.Bound(c => c.CompanyName);
                    columns.Bound(c => c.ContactName);
                    columns.Bound(c => c.Address);
                    columns.Bound(c => c.City);
                })
                .Pageable(pageSettings => pageSettings.Enabled(true).PageSize(10))
        %>
        <%})
           .Render();
        %>
    

    I would double-check your code to ensure that you are setting the content of the Window correctly, as that seems to be where the issue is coming from.