Monday, September 28, 2015

Specifying a Layout file from an MVC Controller


Even though Intellisense for an MVC Controller may not display the correct Intellisense for changing or specifying the Layout for a specific MVC View, you can use the following syntax to explicitly use a different Layout view before rending an MVC View:

public ActionResult Index()
   //specify the CustomLayout Layout file for the Index view
   return View("Index", "_CustomLayout");

Doing this through the MVC Controller allows you to override Layout values configured directly in the MVC View as well as allows you to dynamically load different Layouts for specific MVC Views.

No comments:

Post a Comment