2

How to create one layout page for a partial view?

Simply in MVC we create _layout.html and configure in viewstart.html page for all view. But in this partial views case how I'll do?

If you know a good example, please provide it to me.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Prabhat
  • 772
  • 1
  • 8
  • 22
  • 1
    Partial views are not to be used like this. A Partial View is like a stand-alone fragment of content that can be added or injected into view – zgood Nov 11 '19 at 19:20
  • Hi @zgood Thanks for information you're right only but I have 3 to 4 partial views which have contain same headers so I'm thinking instead of write everywhere I'm thinking create one layout page and consume in every partial views because tomorrow might be (n) no. of partial views have same header content.. – Prabhat Nov 12 '19 at 03:09
  • You can't, but *Helpers* may be the right way to go : [Reusable components](https://stackoverflow.com/a/23529573/4456593) – Axel Samyn Apr 12 '22 at 14:53

3 Answers3

1

You can't create layout page for partialview because partialview is same as user control in asp.net.

As per your requirement you can create one @RenderSection() and consume for every partialview page.

dotnetguru
  • 26
  • 2
0

As of I understand, you can't use a layout page for a partial view. The partial view is resides under a normal view and this view may have it's own layout page. No need of a layout page for the partial view.

If you decided to do so whatever the concept is: 1. Use a normal view to show the partial view. The normal view have no data except the partial view here. 2. Use your desired layout page for this normal view.

  • Thank you for your answer..I guess this is not my solution..!! – Prabhat Nov 12 '19 at 14:58
  • I'm thinking I'll achieve my requirement using @RenderSection() in mvc. I'm thinking I'll create one @section in one page and I'll add all common field there then I'll consume that in all my partial view...!! – Prabhat Nov 12 '19 at 14:59
0
<partial name="_ButtonScroll" />
gemon01
  • 181
  • 7