Redirect to controller (but with a different master) using a catchall wildcard

后端 未结 6 2080
故里飘歌
故里飘歌 2021-01-01 06:16

I have a problem whereby I want to display a view differently (a different master page), depending on where it came from, but don\'t know where to start...

I have se

6条回答
  •  天涯浪人
    2021-01-01 06:51

    You can change the MasterPage by modifying the ViewResult prior to rendering. For example, a controller action could do:

    public ActionResult TestMP(int? id)
    {
        ViewData["Title"] = "MasterPage Test Page";
        ViewData["Message"] = "Welcome to ASP.NET MVC!";
        ViewResult result = View("Index");
        if (id.HasValue)
        {
            result.MasterName = "Site2";
        }
        return result;
    }
    

    You could accomplish the same thing with an action filter for a more generic solution.

提交回复
热议问题