SIGN UP MEMBER LOGIN:    
ARTICLE

TabStrip and TreeView creation using Telerik in ASP.NET MVC

Posted by Vijay Prativadi Articles | ASP.NET MVC with C# November 30, 2011
Today, we will see how to create a Tabstrip and Treeview using telerik in ASP.NET MVC.
Reader Level:

Today, we will see how to create a Tabstrip and Treeview using telerik in MVC. Let's First begin by creating some basic class as Tab.cs. The Complete Source Code for Tab.cs looks like this:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
 
namespace TelerikMvcApp_Tab.Models
{
    public class
Tab
    {
        public string Text { get; set; }
        public string link { get; set; } 
    }
}


We will now initialize some values to the properties specified, so we will be creating a simple class called TabData.cs. The Complete Source Code for TabData.cs looks like this:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
 
namespace TelerikMvcApp_Tab.Models
{
    public static class
TabData
    {
        public static List<Tab> GetData()
        {
            return new List<Tab>
            {
                new Tab
                {
                    Text="Microsoft",
                    link=
"http://www.microsoft.com/en-us/default.aspx"
                },
                new Tab
                {
                    Text="Facebook",
                    link=
"https://www.facebook.com/"
                },
                new Tab
                {
                    Text="StackOverFlow",
                    link=
"http://stackoverflow.com/"
                },
                new Tab
                {
                    Text="C-SharpCorner",
                    link=
"http://www.c-sharpcorner.com/"
                }           
            };
        }
    }
}


It's time for us to go and code in HomeController. We will be calling the GetData Method of the TabData Class to ViewData attribute of Index Action. The Complete Code of HomeController.cs looks like this:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using TelerikMvcApp_Tab.Models;
namespace TelerikMvcApp_Tab.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            ViewData.Model = TabData.GetData();
            return View();
        }
        public ActionResult About()
        {
            return View();
        }
    }
}

Now, we will create a Index View where will use Telerik Extension for TabStrip an TreeView Creation. So the Complete Source Code for this looks like:

@model IEnumerable<TelerikMvcApp_Tab.Models.Tab>
@{ Html.Telerik().TabStrip()
.Name("TabStrip1")
.BindTo(Model,
(item, navigationData) =>
{
item.Text = navigationData.Text;
item.Url = navigationData.link;

})
.Render();
}
<div>
@{ Html.Telerik().TabStrip()
.Name("TabStrip2")
.Items(p =>
{
p.Add().Text("Model-View-Controller").Content(@<p>This is a Model View Controller</p>);
p.Add().Text("WPF").Content(@<p>This is a XAML Code</p>);

})

.Effects(f => f.Expand().Opacity().OpenDuration(300).CloseDuration(300)).Render();

}

<br />
<br />

@( Html.Telerik().TreeView()
.Name("Treeview1")
.Items(p =>
{
p.Add().Text("MVC").Expanded(true)
.Items(r =>
{
r.Add().Text("Model");
r.Add().Text("View");
r.Add().Text("Controller");

});
p.Add().Text("WPF")
.Expanded(true)
.Items(r =>
{
r.Add().Text("XAML");
});

p.Add().Text("Telerik").Expanded(true).Items(o =>
{
o.Add().Text("NumericTextBox");
o.Add().Text("Menu");
o.Add().Text("Grid");
o.Add().Text("Editor");
o.Add().Text("Tab");
o.Add().Text("DropDown");
});

})
)
</div>

The Output for this application looks like this:

TabStrip and TreeView.png

TabStrip and TreeView.png

I hope this article is useful for you. I look forward for your comments and feedback.Thanks Vijay Prativadi.

Login to add your contents and source code to this article
share this article :
post comment
 
Team Foundation Server Hosting
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
    Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites - Click Here!
Become a Sponsor