Published on: 29 December, 2015

How to set layout template in Controller class in MVC?

Tumblr Digg Google Plus

Normally when you want to set a separate layout in MVC, you need to set this manually in the cshtml file. Alternatively, you can now set it automatically in behind code according to specific condition you want.

See the following code example.

var layout = "";
     layout = "_firstLayout";
}else if(condition2){
     layout = "_secondLayout";

//on your return view at the end of the code, you can use the following code.
 return View("index", layout ); 


There are no comments available.

Write Comment
0 characters entered. Maximum characters allowed are 1000 characters.