Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVC4 - ContextDependentView - What does it mean?

I have just started using MVC4 and the first action method that I look at has something new. I checked out the internet and can't find anything about this:

public ActionResult LogOn()
        {
            return ContextDependentView();
        }

Does anyone know what a ContextDependentView is ?

Something new to me.

like image 935
Samantha J T Star Avatar asked Feb 01 '12 13:02

Samantha J T Star


1 Answers

It's purpose is to facilitate View or PartialView action results for the Login and Register actions.

    private ActionResult ContextDependentView()
    {
        string actionName = ControllerContext.RouteData.GetRequiredString("action");
        if (Request.QueryString["content"] != null)
        {
            ViewBag.FormAction = "Json" + actionName;
            return PartialView();
        }
        else
        {
            ViewBag.FormAction = actionName;
            return View();
        }
    }

Like other things in MVC it is done by convention... the convention here is when the Request.QueryString contains a ?content=xxxx, it prepends "Json" to the action name, stuffs it a ViewBag property and returns the partial version of the View. For example:

A request for /Account/Login?content=test would be resolved to ViewBag.FormAction = "JsonLogin"; and then return a partial.

A request for /Account/Login has no content query string so its form action remains ViewBag.FormAction = "Login";

like image 194
one.beat.consumer Avatar answered Oct 20 '22 08:10

one.beat.consumer