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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:10:33+00:00 2026-05-27T16:10:33+00:00

I am programming using ASP.NET MVC 3 with Razor view engine. Here’s what I’d

  • 0

I am programming using ASP.NET MVC 3 with Razor view engine. Here’s what I’d like be able to do:

@Html.DisplayWithLabel(model => model.DisplayEventDate(), "When", "")

DisplayWithLabel is a custom HTML helper that shows something with a label.

Here’s its signature (or at least what I think it should look like):

public static MvcHtmlString DisplayWithLabel<TModel>(this HtmlHelper<TModel> html, Expression<Func<TModel, Func<MvcHtmlString>>> expression, string label, string cssClass)

Why I am using my model like this? Well I’d like to have extensions methods for my model that will help me format its data when it’s necessary (instead of formatting data inside my model itself). For example to format the event date I have this extension method:

public static MvcHtmlString DisplayEventDate(this MyEntity entity)
{
    return new MvcHtmlString(string.Format("{0}@{1}", string.Format("{0:D}", entity.EventDate),
                             string.Format("{0:t}", entity.EventDate)));
}

But when I try to browse the view I am getting an error saying that it’s not possible to implicitly convert from MvcHtmlString to Func<MvcHtmlString>.

I tried to figure it out myself but I couldn’t find a clue so please help me 🙂

  • 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-27T16:10:34+00:00Added an answer on May 27, 2026 at 4:10 pm

    You should be able to do something like this:

    public static MvcHtmlString MyMethodName<TModel, TValue>(
        this HtmlHelper<TModel> html,
        Expression<Func<TModel, TValue>> expression,
        string myText) {
        var exprValue = ModelMetadata.FromLambdaExpression(expression, 
                          htmlHelper.ViewData).Model;
    
        var builder = new TagBuilder("label");
        builder.SetInnerText(myText + " " + exprValue.ToString());
        return MvcHtmlString.Create(builder.ToString());
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Some site I'm programming is using both ASP.NET MVC and WebForms. I have a
I'm a .NET Developer, primarily using c#, asp.net mvc, entity framework and programming for
In looking at the latest release of the Razor view engine with ASP.NET web
Most of my programming experience has either been using forms (Windows Forms, or ASP.NET)
I am new to programming. Using C# & ASP.Net, how would I differentiate between
I have a web site built using asp.net with ugly URLs like /DisplayContent.aspx?id=789564 .
I would like to try developing ASP.NET and ASP.NET MVC apps in F# .
I am currently programming an ASP .NET FormView. The twist here is that I
Like many others on this site I am considering a move to ASP.NET MVC
I am trying to write a web application using ASP.NET MVC . I prefer

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.