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 6594175
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:46:37+00:00 2026-05-25T17:46:37+00:00

In Asp.net MVC3 when you write below code , it generates wrapping html itself

  • 0

In Asp.net MVC3 when you write below code , it generates wrapping html itself

 @using (Html.BeginForm()) {
                @Html.ValidationMessageFor(model => model.Text)
}

It generates codes in below format,

<form method="post" action="/Feeds">
   <!-- Fields Here -->
</form>

My question in @using (Html.BeginForm()) automatically adds <form> tag at beginning and end, how can i create something like that of my own.

I am looking for some thing like below

@using (Html.BeginMYCUSTOMDIV())
  {
        I am text inside div
  }

Expected Generated Output

<div class="customDivClass">
I am text inside div
</div>
  • 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-25T17:46:37+00:00Added an answer on May 25, 2026 at 5:46 pm

    Something along the lines:

    public class MyDiv : IDisposable
    {
        private readonly TextWriter _writer;
        public MyDiv(TextWriter writer)
        {
            _writer = writer;
        }
    
        public void Dispose()
        {
            _writer.WriteLine("</div>");
        }
    }
    
    public static class MyExtensions
    {
        public static MyDiv BeginMYCUSTOMDIV(this HtmlHelper htmlHelper)
        {
            var div = new TagBuilder("div");
            div.AddCssClass("customDivClass");
            htmlHelper.ViewContext.Writer.WriteLine(div.ToString(TagRenderMode.StartTag));
            return new MyDiv(htmlHelper.ViewContext.Writer);
        }
    }
    

    and in the view:

    @using (Html.BeginMYCUSTOMDIV())
    {
        <span>Hello</span>
    }
    

    generates:

    <div class="customDivClass">
        <span>Hello</span>
    </div>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm going to have to write a big system in January with ASP.NET MVC3
I'm trying to write a really simple prototype of a CMS system using ASP.Net
I had wrote a web site using asp.net mvc3 and used Membership class for
I am using ASP.NET MVC 3 and NUnit . I am trying to write
I want to write a web site using ASP.NET MVC 3.0 and Microsoft technologies.
Using ASP.net MVC3 with C# I want to create a partial view that uses
When adding a controller in ASP.Net MVC 3 using Controller with Read/Write actions and
I use asp.net mvc3 and I want to write route that has no end..
ASP.Net: In code-behind I can simulate <%# Eval(Property)%> with a call to DataBinder.Eval(myObject,Property); How
ASP.NET MVC - what is this in VB.NET? Html.TextBox( name, null, new { @class

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.