skip to Main Content

Currently, I am upgrading .NET MVC to .NET Core MVC. In MVC we are using a method like below so I need to keep that logic and it’s used in lots of places. so can you help to find a way to set the Layout page from .NET Core Controller?

return View ("NameOfView",masterName:"viewName");
How to set layout from controller

2

Answers


  1. Chosen as BEST ANSWER

    In this case, we can set it in _ViewStart file using ViewData.

    enter image description here


  2. You could find the difference of ViewResult between asp.net and asp.net core
    Asp.Net Core
    enter image description here
    Asp.Net
    enter image description here

    enter image description here

    enter image description here
    there’s no method supplied for your to set layout in controller the sameway with which you set masterpage in asp.net controller

    You could set masterpage in your view Like:

    @{
        Layout = "_myLayoutPage";
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search