Telerik Extensions for ASP.NET MVC

Version Q1 2012, released 04/19/2012

Column Command

Order ID
Filter
Contact Name
Filter
Ship Address
Filter
 
10248Paul Henriot59 rue de l'AbbayeCustomer Details
10249Karin JosephsLuisenstr. 48Customer Details
10250Mario PontesRua do Paço, 67Customer Details
10251Mary Saveley2, rue du CommerceCustomer Details
10252Pascale CartrainBoulevard Tirou, 255Customer Details
10253Mario PontesRua do Paço, 67Customer Details
10254Yang WangHauptstr. 31Customer Details
10255Michael HolzStarenweg 5Customer Details
10256Paula ParenteRua do Mercado, 12Customer Details
10257Carlos HernándezCarrera 22 con Ave. Carlos Soublette #8-35Customer Details
Displaying items 1 - 10 of 830

About this example ASPXRazor

This example shows how to use a custom column command in Telerik Grid for ASP.NET MVC. Custom commands can be configured to call action methods by making server side or ajax requests. In this particular example the custom command is requesting JSON from an action method and displays it using Telerik Window for ASP.NET MVC

To define a custom column command use the following code

View:
<%= Html.Telerik().Grid(Model)
        .Name("Grid")
        .Columns(columns => columns
            {
            columns.Command(commands => 
                // Define a custom command
                commands.Custom("viewDetails")// the constructor accepts the name of the custom command (used to differentiate between multiple custom commands)
                    // Set the text of the button
                    .Text("Customer Details")
                    // Specify which fields from the bound data item to include in the route (pass as action method arguments)
                    .DataRouteValues(route => route.Add(o => o.OrderID).RouteKey("orderID"))
                    // Make ajax requests
                    .Ajax(true)
                    // Which action method to call
                    .Action("ViewDetails", "Grid")    
                ));
            }
        )
%>
Controller:

public JsonResult ViewDetails(int orderID) // this argument comes from the data item (defined via DataRouteValues)
{
    // Get the order by the specified orderID
    var order = GetOrders()
                    .FirstOrDefault(o => o.OrderID == orderID);

    return Json(new { customer = order.Customer });
}

Get more than expected!

Take the Telerik Extensions for ASP.NET MVC to your Visual Studio projects to truly experience their power. Download your free copy now and jumpstart your development with the available learning resources.

The Extensions are offered in both open source and commercial versions the differences between which are well explained in the licensing FAQ.

If you have any questions, do not hesitate to contact us at sales@telerik.com.

Other Demos: