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

  • SEARCH
  • Home
  • 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 813091
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T01:18:16+00:00 2026-05-15T01:18:16+00:00

Is there a way to make helper in Asp.Net MVC to wrap other html

  • 0

Is there a way to make helper in Asp.Net MVC to wrap other html like this:

<div class="lightGreyBar_left">
    <div class="lightGreyBar_right">

        <!--Content-->
        <h3>
            Profiles</h3>
        <div class="divOption">
            <%= Html.ActionLinkWithImage("Create new", "add.png", Keys.Actions.CreateProfile, "add")%>
        </div>
        <!--Content-->

    </div>
</div>

So that helper will render containing divs and content that is passed to helper method as parameter.

  • 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-15T01:18:17+00:00Added an answer on May 15, 2026 at 1:18 am

    Have a look at the forms helper methods. They provide syntax like this:

    <% using (Html.BeginForm()) { %>
        <p>Form contents go here.</p>
    <% } %>
    

    The pattern for implementing this sort of HTML helpers is slightly more involved than the usual “just return a HTML string” type helpers. Basically, your helper method will Response.Write the opening tag(s) when it is called and return some custom object that implements IDisposable. When the return value is disposed, it should Response.Write the closing tag(s).

    Here is a working example:

    public static MyContainer WrapThis(this HtmlHelper html)
    {
        html.ViewContext.HttpContext.Response.Write("<div><div>");
        return new MyContainer(html.ViewContext.HttpContext.Response);
    }
    
    public class MyContainer : IDisposable
    {
        readonly HttpResponseBase _httpResponse;
        bool _disposed;
    
        public MyContainer(HttpResponseBase httpResponse)
        {
            _httpResponse = httpResponse;
        }
    
        public void Dispose()
        {
            if (!_disposed)
            {
                _disposed = true;
                _httpResponse.Write("</div></div>");
            }
    
            GC.SuppressFinalize(this);
        }
    }
    

    This will allow you to rewrite your view to this:

    <% using (Html.WrapThis()) { %>
        <h3>Profiles</h3>
        <div class="divOption">
            <%= Html.ActionLinkWithImage("Create new", "add.png", Keys.Actions.CreateProfile, "add")%>
        </div>
    <% } %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Client Id for Property (ASP.Net MVC) Is there a way to make
I'm trying out ASP.NET MVC Framework and would like to create an ajax helper
I am using asp.net mvc and I am not sure how to approach this
I have written an ASP.NET HttpModule and I have a static helper class that
I know of the ASP.NET MVC ActionLink helper for generating links to the application's
In asp.net mvc I always see the built in html helpers they always have
I'm using a helper class to build my hyperlink. The markup looks like this:
I found this question Can't use relative paths with areas in ASP.NET MVC 2
Is there a way to make a button's background color change from a color
Is there a way to make MySQL cause some kind of error when doing

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.