2) I registered a custom route to handle any custom / application specific content that
needed to rendered. This is called via the script from step 1.
routes.Add(new Route("Custom/CustomAction",
new MvcRouteHandler())
{
Defaults = new RouteValueDictionary(new { controller = "Custom",
action = "CustomAction” }), }
);
3) I added and partial view called _CustomPartialView (an .ascx page) into my view structures
to handle the
display of the custom/application specific content.
4) Within the Custom controller, I wired up a call to render the partial view
public ActionResult CustomAction()
{
//Gather up all the custom specific data
return View("_CustomParialView");
}
So how does this all piece together, it’s really quite simple. When the main page renders it makes another request via AJAX and JQuery magic to
the Custom controller. The CustomAction action within that controller gathers up all the application specific
data and hands that off to the _CustomParialView partial view. That _CustomPartialView html is then handed back to the original AJAX request and
the resultant html is placed inside the centerbody div placeholder. Now this
approach is relevant irrespective of the CMS system I described here. In short it will work when we want to “plug in” partial views into our pages. So
what makes this approach useful? First we can have nice modular partial views that we can then piece together on pages
was we see fit. These partial views can be structured to be truly small reusable components.
This was a very brief article but a useful technique that I thought I would share.