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

Asked

Viewed 142 times

0

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

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

Is there any way to do that?

2 answers

0

Good night, M. Career,

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

So that all your Views inherit this layout contained in _Layout.cshtml automatically, you should check if the file Viewstart.cshtml ( inside the Views folder of your project) is like this:

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

If so, anything on_Layout.cshtml will be applied to all your views, no need for you to repeat code page by page;.

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

If you have any difficulties, talk to me :D

  • I already know that dear colleague! But as I said, my contact page contains a form, so it is a Web Form and not a View. If I was a View I wouldn’t be asking this question :)

0

have you tried using @rendersection? On the main page, which you want to integrate the Forms, enter:

 `@Rendersection("@nomedaestrutura", bool)`

on the page you want to pull the buttons:

@Section nomedaestrutura{
(form)
(input)
(/forms)
}

and exchange relatives for smaller and larger signals to open and close HTML tags.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.