ASP.Net MVC- How to change master page for a view at runtime?
By [)ia6l0 iii
You can pass the master page name when you return the ViewResult from the Controller's Action.
For e.g, this would return the ViewResult with a new master page name.
public ActionResult TestToChangeMasterPage()
{
var view = View();
view.MasterName = "newMasterPageName";
return view;
}
Related FAQs
Use the ActionLink overloaded method that takes the html attributes that would be applied to the generated link.
There are many threads on the internet that tell you to play with Session or any other web.config values to get Global.asax events working. If they do not work, then this tip is for you.
To stop a robot from visiting your website and causing undesirable robot traffic and many other problems, follow one of the below said three ways:
One of the best ways is to use the RouteConstraint to validate the route values and then choose a route to controller. Route values that hold values of integer is the best example. If the route value is passed as string which cannot be converted to an Integer, we suffer with run-time and unhandled exceptions on our code.
Use Page.ClientQueryString to get the encoded query string portion of the requested url.
Use Page.MaintainScrollPositionOnPostBack to retain the scroll position after a postback.
You can set it as a page directive:
ASP.Net MVC- How to change master page for a view at runtime? (661 Views)