Published on: 29 December, 2015

How to set layout template in Controller class in MVC

Posted by andy | 771 views 0 likes 0 favourites 0 comments
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 = "";
if(condition1){
     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 ); 
Comments

There are no comments available.

Write Comment
0 characters entered. Maximum characters allowed are 1000 characters.
Share your article with us and add your own google adsense account to earn extra money. Plus, you can promote a link back to your site.
Related Articles
Published on: 27 October, 2017
In this article, you will learn how to download a file in Web API MVC. We will use HTTP Get API method to perform this download action with one single parameter which will accept the file name.
Published on: 28 October, 2016

In this tutorial you will learn how easily you can implement a simple checkout express using C# MVC Web API. We will create a really simple shopping cart where customers can add and delete their cart items before proceed to payment.