tags:

views:

55

answers:

1

I have several pages, notably FAQ, testimonials, videos for which I want to provide an external partner with a link to. The content will be embedded inline on their site, or shown as a popup. This is for an ASP.NET MVC site.

Desired bahavior :

  • I need to specify a different 'mode', such as 'popup', or 'inline' for 'css-free' markup
  • At some point I may need more advanced versions of the page using additional query parameters. This is why I'm using query parameters - so I can add or remove things easily. I don't think the desired 'view' should be determinedupon any of the action parameters.
  • Providing a different master page usually isn't a sufficient solution becasue the content may need to be formatted differently.

What I'm providing here is a fully working solution that I'm currently using. I'm just throwing it out here to see if

a) there are any glaring omissions - I'm about to release this into the wild

b) there is built in functionality of the framework I'm forgetting to use

c) if its useful to anyone else.

There are three View files, FAQ.aspx which is the primary page that I will be using on the main site. This includes the partial view FAQContent.ascx. There is also FAQPopup.ascx which also includes FAQContent.ascx, but with a different css file and no master page.

  public class QuestionsController : Controller
    {
        [OutputCache(CacheProfile = "ContentPage", VaryByParam = "mode")]
        public ActionResult FAQ(string mode)
        {
            // determine mode
            if (mode == "popup")
            {
                // popup mode
                return FAQPopup();
            }
            else if (mode == "inline")
            {
                // popup mode
                return FAQContent();
            }

            else
            {
                // normal mode
                FAQModel model = new FAQModel()
                {
                };
                UpdateModel(model);

                return View(model);
            }
        }

        [OutputCache(CacheProfile = "ContentPage")]
        public ActionResult FAQPopup()
        {
            FAQModel model = new FAQModel()
            {

            };
            UpdateModel(model);

            return View("FAQPopup", model);
        }

        [OutputCache(CacheProfile = "ContentPage")]
        public ActionResult FAQContent()
        {
            FAQModel model = new FAQModel()
            {

            };
            UpdateModel(model);

            return View("FAQContent", model);
        }
    }
A: 

Phil Haack wrote a great article handeling the output based on the extension of the request.

http://haacked.com/archive/0001/01/01/handling-formats-based-on-url-extension.aspx

Chad Moran