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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T19:23:35+00:00 2026-06-01T19:23:35+00:00

Previous to MVC, when webforms was the only thing we had, I used to

  • 0

Previous to MVC, when webforms was the only thing we had, I used to define a container for my controls (A Box you may call) and used this web control (with title, body and a couple of other properties) in other controls.

So if I wanted to change the look of all my visual controls, I just had to make one change in my Box control.

Here’s a simplified snippet of what I used to do:

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Box.ascx.cs" Inherits="WebApp.Controls.Box" %>
<span class="boxtitle">
    <asp:Literal ID="ltrTitle" runat="server"></asp:Literal>
</span>
<div class="boxContent" id="dvBox">
    <asp:PlaceHolder runat="server" ID="BoxBodyContainer"/>
</div>

And in code-behind:

public Control BoxBody { get; set; }
public string Title
{
    get { return this.ltrTitle.Text; }
    set { this.ltrTitle.Text = value; }
}
protected void Page_Load(object sender, EventArgs e)
{
    this.BoxBodyContainer.Controls.Add(this.BoxBody);
}  

So I could use this along with other controls in my page as follows:

<MyControls:Box ID="Box1" Title="Foo" runat="server">
    <boxbody>
        <MyControls:CustomControl ID="Bar" runat="server" >
         </MyControls:CustomControl>
    </boxbody>
</MyControls:Box>  

In order to have something alike in MVC 3, I think I should define a Box view and wherever I need the box, use Html.Partial or Html.Action and pass all my data (title, boxbody, etc) to this view and use @Html.Raw in Box view.
But I was wondering if there’s any better, more standard way to achieve this.
What’s the correct way of achieving this in MVC 3 (Razor)?

  • 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-06-01T19:23:37+00:00Added an answer on June 1, 2026 at 7:23 pm

    You can create an Html Helper extension method to do this. The best tutorial I could find was for MVC2, but it gives you the basics.

    What the tutorial doesn’t cover is that there are classes in the System.Web.MVC namespace that can help you create html in code.

    Note: The following code hasn’t been tested.

    using System;
    using System.Web.Mvc;
    
    public static class HtmlExtensions
    {
        public static MvcHtmlString Box(this HtmlHelper helper, string title, MvcHtmlString body)
        {
            TagBuilder span = new TagBuilder("span");
            span.AddCssClass("boxtitle");
            span.SetInnerText(title.ToString());
    
            TagBuilder div = new TabBuilder("div");
            div.AddCssClass("boxContent");
            div.InnerHtml = body;
    
            return MvcHtmlString.Create(span.ToString() + div.ToString());
        }
    }
    

    You can call this method from the razor view like so:

    @Html.Box("foo", Html.Partial("bar"))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working through a previous webforms application to convert it to MVC and have
I am refactoring a web app built with previous versions of Asp.Net MVC where
Solved using this post: Can you convert an ASP.NET MVC Application to a Web
From previous experience I had been under the impression that it's perfectly legal (though
In previous question of mine, someone had meantioned that using Semaphores were expensive in
Our previous webmaster set up this site and the caching he set up works
Using MVC 2, if I setup my root web.config with forms authentication (there is
My ASP.NET MVC web app has a weird issue. In VS debugging mode it
I'm writing web application that uses Spring MVC to bind Spring beans with REST-like
My question stems from MVC's SelectList (and previous generations). Basically the class takes in

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.