I created a .NET Core 3.1 ASPNET project. By default, the startup page us the Home Controller/Index page.
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
});
But I want to make a Login Page, so I Created a New Controller with a new Action and I passed on the parameter, but instead of ONLY render the Login Page, it renders inside of the "@RenderBody()" from the layout project. On .NET MVC5 it only rendered the page that I set. I already tried with :
app.UseMvc(routes =>
{
routes.MapRoute("default", "{controller=Home}/{action=Index}/{id?}");
});
And it's the same thing. The login page it's not rendered apart of the layout
This has nothing to do with routing.
If you look in your Views folder, there will be a file called _ViewStart.cshtml, containing this code:
@{
Layout = "_Layout";
}
_ViewStart.cshtml runs for every view, so by default it sets the layout page to _Layout.cshtml.
There are 2 options:
Layout
needs to be explicitly set in each view.Layout
to null
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.