Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6682815
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:44:58+00:00 2026-05-26T04:44:58+00:00

Razor doesn’t support same-page sections, so I can’t do something like this: @if (wrapSection)

  • 0

Razor doesn’t support same-page sections, so I can’t do something like this:

@if (wrapSection)
{
    <div class="section-wrapped-in-div">
        @RenderSection("mySection")
    </div>
}
else
{
    @RenderSection("mySection")
}

@section mySection
{
    some stuff here...
}

I know I can accomplish this with a partial view, but this is specific to this page, and really would be best kept on the same page.

Is something like this possible?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T04:44:58+00:00Added an answer on May 26, 2026 at 4:44 am

    You should make a helper method:

    @helper MySection(...) {
        ...
    }
    
    @MySection(...)
    

    Unlike sections, helpers can also take parameters.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can I reduce this razor code? <li> @{ if (@Model.PublicationDate.HasValue) { @Model.PublicationDate.Value.ToString(D, new System.Globalization.CultureInfo(fr-FR))
I have a razor view that looks like this @using(Html.BeginForm(MVC.Account.Info())) { <p>blah blah blah</p>
I have a string created using asp.net MVC3 Razor block like this: @{ var
I am running the following code on an ASP.NET razor page (cshtml) and am
Razor looks like a winner for developers...close to the metal, yet quick and efficient.
I have the following section of Razor code and it fails during runtime with
Here is what I would like to express by Razor: <b>@parameterMapping.Title</b> (Category: @parameterMapping.Category.Title, Regexp:
The CSS3 @font-face rule breaks a Razor section with the error message: CS0103: The
I have an ASP.NET MVC 3 (Razor) Web Application, with a particular page which
I've a following asp.net mvc razor view code which doesn't seem to be working:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.