How to set up a program page for MVC2

In simple ASP.NET, this is a simple task ... just override Page_PreInitand do it!

but how to do it in ASP.NET MVC2 ?

+3
source share
2 answers

This is even easier in ASP.NET MVC, just enter the name of the main page as the second parameter:

return View("MyView", "MyMasterPage");

Of course, you can also create your own System.Web.Mvc.ViewPageand change the main page there.

+5
source

you can also do this in an override (in the controller or base controller) if you have some actions that are shared between the admin and user site:

protected override ViewResult View(string viewName, 
                                   string masterName, object model)
{

    // we share some views that aren't partialviews
    // therefore, we have to ensure that the Shareholder master template
    // is ALWAYS attached to the logged in user if they aren't an admin user
    bool userIsAdmin = IsAuthorised("Admin");

    if (!userIsAdmin) // then flip the masterpage to Shareholder.Master
    {
        masterName = "Shareholder";
    }

    return base.View(viewName, masterName, model);
}

, , :)

+2

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


All Articles