For some reasons I have to Redirect my page from Account Controller -> Login method to
Home Controller -> Index method. That's what I am doing.
public class AccountController : Controller
{
public ActionResult Login()
{
//return View();
return RedirectToAction("Index", "Home");
}
}
My problem is when the redirect happens the layout page used by the Razor View Engine is the same used by
Login Action Method. not the one used by Index Logically, when we Redirect the Razor engine should use the New Layout page defined in the
Index View
I read your post a few times and I have no idea what you're asking. Did you add multiple layout pages and are having a problem assigning the layout pages? What kind of project are you building? Is this ASP.NET MVC or maybe ASP.NET Core MVC?
I am developing a small system using ASP.NET MVC. Yes I do have multiple layout pages, I have two layout pages for two different index pages.
My problem is when I try to redirect from the Index action method to another Index method in a different controller the layout page didn't got changed. Even though I explicitly define the Layout in my view (in the Destination View).
I cannot reproduce this issue. The layout page I assign in the View is the layout that's rendered when the View is rendered. A redirect has nothing to do with the layout page.
Is it possible to share your project in GIT so the community can reproduces this issue?
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
Member
39 Points
96 Posts
Redirect to Action issue.
Feb 01, 2020 09:52 AM|jalali|LINK
Dear Friends.
For some reasons I have to Redirect my page from Account Controller -> Login method to Home Controller -> Index method. That's what I am doing.
My problem is when the redirect happens the layout page used by the Razor View Engine is the same used by Login Action Method. not the one used by Index Logically, when we Redirect the Razor engine should use the New Layout page defined in the Index View
Can anybody help me with this?
All-Star
53051 Points
23634 Posts
Re: Redirect to Action issue.
Feb 01, 2020 12:46 PM|mgebhard|LINK
I read your post a few times and I have no idea what you're asking. Did you add multiple layout pages and are having a problem assigning the layout pages? What kind of project are you building? Is this ASP.NET MVC or maybe ASP.NET Core MVC?
Member
39 Points
96 Posts
Re: Redirect to Action issue.
Feb 01, 2020 04:07 PM|jalali|LINK
I am developing a small system using ASP.NET MVC. Yes I do have multiple layout pages, I have two layout pages for two different index pages.
My problem is when I try to redirect from the Index action method to another Index method in a different controller the layout page didn't got changed. Even though I explicitly define the Layout in my view (in the Destination View).
All-Star
53051 Points
23634 Posts
Re: Redirect to Action issue.
Feb 01, 2020 04:56 PM|mgebhard|LINK
I cannot reproduce this issue. The layout page I assign in the View is the layout that's rendered when the View is rendered. A redirect has nothing to do with the layout page.
Is it possible to share your project in GIT so the community can reproduces this issue?
SO Post.
https://stackoverflow.com/questions/5161380/how-do-i-specify-different-layouts-in-the-asp-net-mvc-3-razor-viewstart-file/5161384
Participant
1320 Points
491 Posts
Re: Redirect to Action issue.
Feb 03, 2020 06:49 AM|jiadongm|LINK
Hi jalali,
I made a test baesd on your description, and it will render the different layout if you have define it in the view.
I copied the default layout page and renamed it as _Layout2.cshtml under the Shared folder, I changed the names of some tags to distinguish them.
Shared folder:
Controller:
Account Index View:
@{ ViewBag.Title = "Index"; Layout = "~/Views/Shared/_Layout2.cshtml"; } <h2>Index</h2> @Html.ActionLink("Login", "Login", "Account")
Home Index View:
@{ ViewBag.Title = "Index"; Layout = "~/Views/Shared/_Layout.cshtml"; } <h2>@ViewBag.Title.</h2>
Result:
Best Regards,
Jiadong Meng