Blogs

News

Email Subscriptions

Mehul Harry's DevExpress Blog

ASP.NET MVC - How To Embed MVC GridView Extension In To Tab Strip Extension

     

Check out this quick little how-to guide for embedding the DevExpress MVC GridView into the Tab Strip Extension.

Background

Alexey M. asked the following question on our forums:

MVC Tabs Demo and GridView components

By Alexey X in MVC Extensions

Hello! I'm using demo with AJAX tabbed page. I want to place a data grid into one of the ajax-tab. How I can do it?

Solution

Our Tab Strip extension has a slick 'AJAX' demo that shows off it's callback capabilities when clicking on the different tabs:

image

To embed our MVC GridView extension into the Tab Strip extension, follow these steps:

1. Create a View called TabControl.aspx and add the following code:

<% Html.RenderPartial("TabControlPartial", Model); %>

2. Create the 'TabControlPartial.ascx' view and add the following code for the tab strip extension:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>

<% 
    Html.DevExpress().PageControl(settings => {
        settings.Name = "pageControl";
        settings.CallbackRouteValues = new { Controller = "Home", Action = "TabControlPartial" };

        settings.TabPages.Add("page1");
        settings.TabPages.Add(tabPage => {
            tabPage.Text = "page2";
            tabPage.SetContent(() => { 
                Html.RenderPartial("GridViewPartial", Model);
            });
        });
    })
    .Render(); 
%>

3. Create the 'GridViewPartial.ascx' view and add the following code for the GridView extension:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
<%
    Html.DevExpress().GridView(settings => {
        settings.Name = "Grid";
        settings.CallbackRouteValues = new { Controller = "Home", Action = "GridViewPartial" };

...
    })
    .Bind(Model)
    .Render();    
%>

4. Be sure to have your methods also defined in your Controller. In the sample above, I'm referencing the HomeController.cs:

...
        public ActionResult TabControl() {
            return View(GetData());
        }
        public ActionResult TabControlPartial() {
            return PartialView(GetData());
        }
        public ActionResult GridViewPartial() {
            return PartialView(GetData());
        }

...

If want to convert the above code to the 'Razor' view engine then please check out these excellent resources:

Enjoy and thanks for using the DevExpress MVC Extensions!

Build Your Best - Without Limits or Compromise

Try the DevExpress ASP.NET MVC Extensions online now: http://mvc.devexpress.com

Read the latest news about DevExpress ASP.NET MVC Extensions

Download a free and fully-functional version of DXperience now: http://www.devexpress.com/Downloads/NET/

Follow MehulHarry on Twitter

Published Jun 15 2011, 08:00 AM by Mehul Harry (DevExpress)
Technorati tags: How-To, ASP.NET MVC, MVCxGridView
Bookmark and Share

Comments

 

Alexey X said:

Hello!

I'm getting such exception at aspx-file:

c:\Documents and Settings\MoiseevAI\My Documents\Dropbox\ISG\CS\trunk\MVCDemos\Views\Request\CallbacksPartial.ascx(4): error CS1660: Cannot convert lambda expression to type 'DevExpress.Web.Mvc.PageControlSettings' because it is not a delegate type

Could you please explain me - what I need to read, to understand?

June 15, 2011 4:17 AM
 

Mike (DevExpress Support) said:

Hello Alexey,

This issue is caused by the fact that any expression in the PageControl's definition is not valid, so that the entire PageControl's definition (lambda expression) cannot be recognized by the View Engine.

Please refer to the original post ([url=community.devexpress.com/.../346904.aspx]community.devexpress.com/.../346904.aspx[/url]) where I published two samples, illustrating how to accomplish this task within both ASPx and Razor View Engines.

June 20, 2011 2:21 AM

About Mehul Harry (DevExpress)

Mehul Harry is an ASP.NET technical evangelist at Developer Express. You can reach him directly at mharry@DevExpress.com. You can also follow him on Twitter: http://twitter.com/mehulharry
More from DevExpress
Live Chat
Have a pre-sales question?
Need assistance with your evaluation?
We are here to help.
Chat is one of the many ways you can contact members of the DevExpress Team. We are available Monday-Friday between 8:30am and 5:00pm Pacific Time.
If you need additional product information, require pre-sales assistance, or want help with your order, write to us at info@devexpress.com or call us at
+1 (818) 844-3383.