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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T12:37:14+00:00 2026-05-19T12:37:14+00:00

New to MVC and have been running through the tutorials on the asp.net website.

  • 0

New to MVC and have been running through the tutorials on the asp.net website.

They include an example of a custom html helper to truncate long text displayed in a table.

Just wondering what other solutions people have come up with using HTML helpers and if there are any best practices or things to avoid when creating/using them.

As an example, I was considering writing a custom helper to format dates that I need to display in various places, but am now concerned that there may be a more elegant solution(I.E. DataAnnotations in my models)

Any thoughts?

EDIT:

Another potential use I just thought of…String concatenation.
A custom helper could take in a userID as input and return a Users full name…
The result could be some form of (Title) (First) (Middle) (Last) depending on which of those fields are available. Just a thought, I have not tried anything like this yet.

  • 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-19T12:37:14+00:00Added an answer on May 19, 2026 at 12:37 pm

    Well in the case of formatting the DisplayFormat attribute could be a nice solution:

    [DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}")]
    public DateTime Date { get; set; }
    

    and then simply:

    @Html.DisplayFor(x => x.Date)
    

    As far as truncating string is concerned a custom HTML helper is a good solution.


    UPDATE:

    Concerning your EDIT, a custom HTML helper might work in this situation but there’s also an alternative approach which I like very much: view models. So if in this particular view you are always going to show the concatenation of the names then you could define a view model:

    public class PersonViewModel
    {
        public string FullName { get; set; }
    }
    

    Now the controller is going to query the repository to fetch the model and then map this model to a view model which will be passed to the view so that the view could simply @Html.DisplayFor(x => x.FullName). The mapping between models and view models could be simplified with frameworks like AutoMapper.

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

Sidebar

Related Questions

I have a new ASP.NET MVC project (my first), and I had been running
Does anyone have links to tutorials regarding the new IModelBinder in asp.net mvc beta?
I'd like to have some of the ScriptManager features in the new Asp.net MVC
I'm new to ASP.NET MVC so this may be a stupid question. I have
i have been working on a new .net MVC site and have integrated some
I have an asp.net mvc application with a route similar to: routes.MapRoute(Blog, {controller}/{action}/{year}/{month}/{day}/{friendlyName}, new
I'm new to MVC (and ASP.Net routing). I'm trying to map *.aspx to a
I have an Asp.Net MVC Web Application that I am developing. I have TeamCity
I have been working on a website using MVC Preview 1 since it came
I have to admit in advance that I'm quite new to MVC, I've been

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.