How to dynamically change homepage in asp.net mvc application

how to dynamically change the home page in an asp.net mvc application. As with ASP.Net, it can be changed in Page_PreInit Event

+3
source share
2 answers

Views display a property .MasterNamethat indicates which main page to use. You can set this in your controller when returning the view.

For instance,

    public ActionResult Index()
    {
        ViewResult vr = View();
        vr.MasterName="....";
        return vr;
    }
+2
source

You can create your own class ViewPageand override the method OnPreInitand set the property accordingly MasterPageFile.

Just change your views to use your own ViewPage class, and you're done.

+1

Source: https://habr.com/ru/post/1746895/


All Articles