14

I have an ASP.NET-MVC3-Layout and use the RenderSection function:

@RenderSection("BackLink", required: false)

How can I call this function twice? I want to render a defined section at multiple places in my layout.

If I use @RenderSection() more than once I get an error.

gunr2171
  • 16,104
  • 25
  • 61
  • 88
Konrad
  • 4,329
  • 10
  • 54
  • 88

1 Answers1

25

Maybe something like:

@var result = RenderSection("BackLink", required: false).ToHtmlString();

First:
@Html.Raw(result);

Second:
@Html.Raw(result);
Paul Tyng
  • 7,924
  • 1
  • 33
  • 57
  • 1
    Is there some other way to do this? According to the MS docs ToHtmlString() as used above should not be used directly in our code only by .NET infrastructure and thus they may change this. – Peter Mar 11 '20 at 14:54