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

  • Home
  • SEARCH
  • 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 533517
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:31:00+00:00 2026-05-13T09:31:00+00:00

Consider an extension method whose purpose is to either: render an <a> tag on

  • 0

Consider an extension method whose purpose is to either:

  • render an <a> tag
  • on some condition, just return a string without a link

 
Question: in an extension method, how can you leverage the proper routing logic with Route Values, etc. rather than hardcoding the string. I suspect HtmlHelper.GenerateRouteLink is part of the solution, but please suggest the best way to achieve this.

public static string CreateUserLink(this HtmlHelper html, string userAcctName)
{
    if (string.IsNullOrEmpty(userAcctName))
        return "--Blank--";

    //some lookup to A.D.            
    DomainUser user = ADLookup.GetUserByAcctName(userAcctName);

    if (user == null)
        return userAcctName;

    //would like to do this correctly!
    return string.Format("<a href='/MyAppName/User/View/{0}' title='{2}'>{1}</a>"
                        , user.Mnemonic, user.DisplayName, user.Location);

    //normally returns http://mysite.net/MyAppName/User/View/FOO
    }

More info:

  • using ASP.NET MVC 1.0

alt text

  • 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-13T09:31:00+00:00Added an answer on May 13, 2026 at 9:31 am

    I just had to do something similar to this yesterday. There may be a slicker way to do it, but it helps me to see exactly what is going on, so I don’t assume anything.

    public static string CreateUserLink(this HtmlHelper html, string userAcctName)
    {
        if (string.IsNullOrEmpty(userAcctName))
            return "--Blank--";
    
        //some lookup to A.D.            
        DomainUser user = ADLookup.GetUserByAcctName(userAcctName);
    
        if (user == null)
            return userAcctName;
    
        RouteValueDictionary routeValues = new RouteValueDictionary();
    
        routeValues.Add("controller", "User");
        routeValues.Add("action", "View");
        routeValues.Add("id", user.Mnemonic);
    
        UrlHelper urlHelper = new UrlHelper(html.ViewContext.RequestContext);
        TagBuilder linkTag = new TagBuilder("a");
    
        linkTag.MergeAttribute("href", urlHelper.RouteUrl(routeValues));
        linkTag.MergeAttribute("title", user.Location);
        linkTag.InnerHtml = user.DisplayName;
    
        return linkTag.ToString(TagRenderMode.Normal);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 346k
  • Answers 346k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer TDD is for sure supported for SL4, what i suggest… May 14, 2026 at 6:11 am
  • Editorial Team
    Editorial Team added an answer It's called Bucket sort. Another approach when main memory is… May 14, 2026 at 6:11 am
  • Editorial Team
    Editorial Team added an answer Have you tried openning the service after you initialize it… May 14, 2026 at 6:11 am

Related Questions

Consider this simple XML document. The serialized XML shown here is the result of
I've put off using generated code as part of the build process for fear
Consider an algorithm that needs to determine if a string contains any characters outside
The idea behind this code is that it uses an extension method to instantiate
What would you consider to be the best exception type to throw when an

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.