user3187771
user3187771

Reputation: 13

How to set layout page for view runtime

I have one application in which I require to set layout file of view runtime depend on parameter. Is it possible in MVC 4 with Razor?

Upvotes: 1

Views: 513

Answers (2)

Kamlesh
Kamlesh

Reputation: 529

You can set Layout ='Path to layout file in shared folder', with this you can change your layout file

@{ 
   var layoutPath ="DefaultPath";
   switch(Parameter){
      case "value1": 
         layoutpath='path1';
         break;
      case "value2" : 
         layoutpath='path2';
         break;
   }
   Layout = layoutpath; 
}

Upvotes: 2

ilay zeidman
ilay zeidman

Reputation: 2814

Try this in your .cshtml file at the start of the page:

@{if (Parameter==value)
{
  Layout = "oneLayout";
}
else
{
  Layout="secondLayoutPath";
}

Upvotes: 0

Related Questions