Click here to Skip to main content
15,897,291 members
Articles / Web Development / HTML

Dynamic Generation of Tabs to Host IFrames using jQuery and Json in ASP.NET MVC

Rate me:
Please Sign up or sign in to vote.
4.82/5 (6 votes)
1 Oct 2010CPOL8 min read 46.9K   1.6K   25  
This article introduces a method to dynamically generate tabs to host IFrames using jQuery and Json in ASP.NET MVC.
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.Mvc;
using DynamicJsonIFrame.Models;

namespace DynamicJsonIFrame.Controllers
{
    [HandleError]
    public class HomeController : Controller
    {
        [AcceptVerbs(HttpVerbs.Get)]
        public ActionResult Index(){ return View(); }

        [AcceptVerbs(HttpVerbs.Get)]
        public ActionResult IFrameContainer(string WebURL,
            string InformationText)
        {
            ViewData["WebURL"] = WebURL;
            ViewData["InformationText"] = InformationText;
            return View();
        }

        [AcceptVerbs(HttpVerbs.Get)]
        public ActionResult IFrameWebLoader(string WebURL)
        {
            ViewData["WebURL"] = WebURL;
            return View();
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult GetTabs()
        {
            List<TabInfo> tabList = new List<TabInfo>();
            tabList.Add(new TabInfo
            {
                TabID = 1,
                TabText = "Yahoo",
                TabInformationText = "",
                TabUrl = "http://www.yahoo.com"
            });
            tabList.Add(new TabInfo
            {
                TabID = 2,
                TabText = "Hall of fame",
                TabInformationText
                    = "Michael Jordan's hall of fame acceptance speech",
                TabUrl = "http://www.youtube.com/watch?v=owbYN3XstVQ"
            });
            tabList.Add(new TabInfo
            {
                TabID = 2,
                TabText = "Soccer Game",
                TabInformationText = "The greatest soccer goal",
                TabUrl = "http://www.youtube.com/watch?v=MsAgu45qqWE"
            });
            tabList.Add(new TabInfo
            {
                TabID = 2,
                TabText = "Cool",
                TabInformationText = "Soccer and soccer !",
                TabUrl = "http://www.youtube.com/watch?v=X5SwdvUWx0E"
            });

            return Json(tabList);
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United States United States
I have been working in the IT industry for some time. It is still exciting and I am still learning. I am a happy and honest person, and I want to be your friend.

Comments and Discussions