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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T11:03:25+00:00 2026-05-21T11:03:25+00:00

I currently have a div container for all of the input fields in my

  • 0

I currently have a div container for all of the input fields in my form, similar to:

<div class="ux-single-field ui-widget-content ui-corner-all">
  @Html.LabelFor(m => m.Name)
  @Html.TextBoxFor(m => m.Name)
</div>

I would like to know how could I encapsulate this using a templated razor delegate (or any other trick), so just like we use:

@using (Html.BeginForm()) {
}

I could simply wrap my elements like:

@using (Html.ContentField()) {
  @Html.LabelFor(m => m.Name)
  @Html.TextBoxFor(m => m.Name)
}
  • 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-21T11:03:26+00:00Added an answer on May 21, 2026 at 11:03 am

    Using the Razor View Engine, here is what works:

    namespace MyProject.Web.Helpers.Extensions
    {
        public static class LayoutExtensions
        {
            public static ContentField BeginContentField(this HtmlHelper htmlHelper)
            {
                return FormHelper(htmlHelper, new RouteValueDictionary());
            }
    
            public static ContentField BeginContentField(this HtmlHelper htmlHelper, RouteValueDictionary htmlAttributes)
            {
                return FormHelper(htmlHelper, htmlAttributes);
            }
    
            public static void EndContentField(this HtmlHelper htmlHelper)
            {
                htmlHelper.ViewContext.Writer.Write("</div>");
            }
    
            private static ContentField FormHelper(this HtmlHelper htmlHelper, IDictionary<string, object> htmlAttributes)
            {
                TagBuilder tagBuilder = new TagBuilder("div");
                tagBuilder.MergeAttributes(htmlAttributes);
                tagBuilder.MergeAttribute("class", "ux-single-field ui-widget-content ui-corner-all");
    
                htmlHelper.ViewContext.Writer.Write(tagBuilder.ToString(TagRenderMode.StartTag));
                return new ContentField(htmlHelper.ViewContext.Writer);
            }
        }
    
        public class ContentField : IDisposable
        {
            private bool _disposed;
            private readonly TextWriter _writer;
    
            public ContentField(TextWriter writer)
            {
                if (writer == null)
                    throw new ArgumentNullException("writer");
    
                _writer = writer;
            }
    
            [SuppressMessage("Microsoft.Security", "CA2123:OverrideLinkDemandsShouldBeIdenticalToBase")]
            public void Dispose()
            {
                Dispose(true /* disposing */);
                GC.SuppressFinalize(this);
            }
    
            protected virtual void Dispose(bool disposing)
            {
                if (!_disposed)
                {
                    _disposed = true;
    
                    _writer.Write("</div>");
                }
            }
    
            public void EndForm()
            {
                Dispose(true);
            }
        }
    }
    

    FYI: Using the old ASPX engine, here’s how to do it.

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

Sidebar

Related Questions

I have something like this currently: <div class = className style = position: absolute;
Okay so say I have a form element like this: HTML: <div class=form-item> <label>Current
I have 2 sets of 4 input fields in my HTML Form. I expect
OK so I have a container div that loads some content which is generated
I have a container for all of my content that is 1000px wide and
I have webpage with a video element nested in a div class=video-container along with
Currently I'm using this: HTML: <div id=container> <img src=x.jpg id=bg /> <div id=content> <h1>Welcome
I currently have a simple setup: a centered container div that is 90% width
I currently have a setup of divs within a container div, as follows: <div
So currently I have: #div { position: relative; height: 510px; overflow-y: scroll; } However

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.