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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T15:08:13+00:00 2026-06-05T15:08:13+00:00

I need to display short description like label and near it data associated with

  • 0

I need to display short description like label and near it data associated with this description.
For editing data it looks like

<div class="field">
    @Html.LabelFor(m => m.CustomerTaxId)
    @Html.EditorFor(m => m.CustomerTaxId)
</div>

Now I want to do the same thing for readonly data. I’ve written next code

<div>
    @Html.LabelFor(m => m.TotalAmount)
    @Html.DisplayFor(m => m.TotalAmount)
</div>

It seems working but it breaks semantic meaning of label tag which must be used for input tags only.
Is there a way in MVC 3 to get something like

<div>
   <span class="label">Total amount</span>
   <span class="value">1500.00 $</span>
</div>

with minimal efforts (think it can be done with heavy template usage)

It seems like I can overwrite template for Html.DisplayFor how to deal with Html.LabelFor?

  • 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-05T15:08:15+00:00Added an answer on June 5, 2026 at 3:08 pm

    You can create custom html helper as below,

    public static MvcHtmlString Span<TModel, TValue>(this HtmlHelper<TModel> html, 
             Expression<Func<TModel, TValue>> expression, object htmlAttributes)
    {
      var metadata = ModelMetadata.FromLambdaExpression(expression, html.ViewData, null);
      string spanInnerText = metadata.DisplayName ?? metadata.PropertyName;
    
      TagBuilder tag = new TagBuilder("span");
      tag.MergeAttributes(HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes));
      tag.SetInnerText(spanInnerText);
    
      return MvcHtmlString.Create(tag.ToString(TagRenderMode.Normal));
    }
    

    You could use in a view as,

    @Html.Span(m => m.Name, new { @class = "label" })
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i need to display value of <input> into the <span> and when label become
I need to switch between the short and the full description of an article.
I would like to have functionality on my site where I could display short
To be short, It's a website for an investigations lab. I need to display
Long story short, I need to display some coloured text with a coloured background
i need to display some data from the DB. I need to display the
I'm trying to make a label display some text, and then after a short
i am developing one application with map view i need display the weather depends
I need to display image and one button on fancybox popup but I can't
I need to display all the employees in one webpart. I created the gridview

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.