Reputation: 13
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
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
Reputation: 2814
Try this in your .cshtml file at the start of the page:
@{if (Parameter==value)
{
Layout = "oneLayout";
}
else
{
Layout="secondLayoutPath";
}
Upvotes: 0