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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:49:41+00:00 2026-05-23T09:49:41+00:00

Question: How do I modify or create my own Html.ActionLink helper to accept and

  • 0

Question: How do I modify or create my own Html.ActionLink helper to accept and handle the first parameter (linkText) passed in as an empty string / nothing?

Details: I currently have a strongly typed view that’s passed a model which contains search results. My view loops through each item in the model and attempts to display a link to a contact with the following code:

@Html.ActionLink(currentItem.ContactName, "contact", "details", New With { .id = currentItem.ContactID }, Nothing)

Normally this would work just fine, but not every item in my search result has a ContactName. The Html.ActionLink helper errors when this first parameter is empty. In case it helps, here’s the model property for ContactName (which is generated from a template due to Database First, so I don’t believe it can be modified):

Public Property ContactName As String

I’d like to have a helper function that simply returns nothing if the ContactName is an empty string / nothing.

I’m guessing I need to extend this helper, and I’ve struggled to find any good, up-to-date resources in VB.net for extending helper functions. Other approaches are more than welcome if they’re considered best practice. I’m working in VB.net, MVC3, and Razor in the ASP.net 4.0 framework. Thanks in advance for your help!

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

    To make this happen, I created a Helpers folder in my solution and added a new module HtmlHelperExtensions.vb which is detailed here (thanks to Darin Dimitrov for the module code):

    Imports System.Runtime.CompilerServices
    
    Namespace MyHtmlHelpers
    Public Module HtmlHelperExtensions
        'Function to extend the ActionLink helper
        'Function will return an empty html string for empty or null linkText values
        <Extension()> _
        Public Function MyActionLink(
                ByVal html As HtmlHelper            , _
                ByVal linkText As String            , _
                ByVal actionName As String          , _
                ByVal controllerName As String      , _
                ByVal routeValues As Object         , _
                ByVal htmlAttributes As Object
            ) As IHtmlString
    
            If String.IsNullOrEmpty(linkText) Then
                Return MvcHtmlString.Empty
            End If
    
            Return html.ActionLink(linkText, actionName, controllerName, routeValues, htmlAttributes)
        End Function
    End Module
    End Namespace
    

    I then had to go into my Web.Config file located in the View folder of my solution in order to add this as a common view namespace, added as namespace=”solutionname.namespace” (note the last add namespace tag):

    <system.web.webPages.razor>
    <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <pages pageBaseType="System.Web.Mvc.WebViewPage">
      <namespaces>
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Routing" />
        <add namespace="BrokerCRM.MyHtmlHelpers" />
      </namespaces>
    </pages>
    

    I then had to close and reopen my views (.vbhtml) for intellisence to work for my new html helper.

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

Sidebar

Related Questions

I have a requirement for users to create, modify and delete their own articles.
This is an extension for this question asked an hour ago. We cannot modify
Question Using XSLT 1.0, given a string with arbitrary characters how can I get
This is a follow-up to this question's answer . How can I modify the
Currently i's look at this question ( How to create a diagonal line within
I have a question on how to create custom View Helpers. I would like,
My application allows users to create and modify files. I would like them to
I am trying to modify the tutorial Ray Wenderlich has created at: http://www.raywenderlich.com/1888/how-to-create-a-simple-iphone-app-tutorial-part-33 So
Anyone knows how to create one? I know this question has been asked before
When you create or modify an object instance in Django's admin, a changelog entry

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.