Is there any way for a form to inherit from _Layout.cshtml in C #?

0

I'm developing a website at asp.net c# , I have a contact page that contains a form for the user to fill out and send if they want to send an email.

I wanted the form page to inherit the properties of the remaining pages of the site, such as the menu and the footer.

Is there any way to do this?

    
asked by anonymous 24.05.2018 / 09:48

1 answer

0

Good evening, M. Carreira,

The _Layout.cshtml file is the default Layout for your views. When you create a project in Visual Studio as Asp.Net MVC, it automatically creates this file. It contains the navigation bar that is at the top of the page, with a few links like, Home, About and Contact the footer as well.

In order for all of your Views to inherit this layout contained in _Layout.cshtml automatically, you should check that the ViewStart.cshtml which is within the Views folder of your project) looks like this:

@{
   Layout = "~/Views/Shared/_Layout.cshtml";
 }

If it is, everything in _Layout.cshtml will apply to all your views, without having to repeat code page by page;

If you want to change the footer or top menu, just change the _Layout.cshtml file that all the changes will be applied to all your Views, including your contact page.

If you have any difficulty, talk to me: D

    
28.05.2018 / 01:42