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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:57:10+00:00 2026-05-23T10:57:10+00:00

I am building a customer ajaxhelper extension in order to create an Ajax.ActionImage(…) method

  • 0

I am building a customer ajaxhelper extension in order to create an Ajax.ActionImage(…) method (see code below).

What I don’t know how to do is “merge” the AjaxOptions into my anchor href attribute. I could use ajax.ActionLink(…) but then I don’t know how t build my image element inside the created MvcHtmlString.

Thanks in advance!

    <Extension()> _
    Public Function ActionImage(ByVal ajax As AjaxHelper, ByVal controller As String, ByVal action As String, ByVal routeValues As Object, ByVal AjaxOptions As Object, ByVal imagePath As String, ByVal alt As String, ByVal width As Integer, ByVal height As Integer) As MvcHtmlString

        Dim url = New UrlHelper(ajax.ViewContext.RequestContext)

        Dim imgHtml As String
        Dim anchorHtml As String
        Dim imgbuilder = New TagBuilder("img")

        imgbuilder.MergeAttribute("src", url.Content(imagePath))
        imgbuilder.MergeAttribute("alt", alt)
        imgbuilder.MergeAttribute("width", width)
        imgbuilder.MergeAttribute("height", height)
        imgHtml = imgbuilder.ToString(TagRenderMode.SelfClosing)

        Dim anchorBuilder = New TagBuilder("a")
        anchorBuilder.MergeAttribute("href", url.Action(action, controller, routeValues))
        anchorBuilder.InnerHtml = imgHtml
        anchorHtml = anchorBuilder.ToString(TagRenderMode.Normal)

        Return MvcHtmlString.Create(anchorHtml)

    End Function
  • 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-23T10:57:10+00:00Added an answer on May 23, 2026 at 10:57 am

    First, you need to change the type of the variable ajaxOptions to AjaxOptions (in the System.Web.Ajax namespace). Once you have done this, you can add the following to merge your ajaxOptions into your anchor tag:

    If ajaxHelper.ViewContext.UnobtrusiveJavaScriptEnabled Then
        anchorBuilder.MergeAttributes(ajaxOptions.ToUnobtrusiveHtmlAttributes())
    End If
    

    You do not want the options inside your href. The options must be part of the anchor tag, in order to be parsed correctly by jquery.unobtrusive-ajax.js.

    counsellorben

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

Sidebar

Related Questions

I'm new to PHP, and building a page that displays a customer order form
I am building an EC website for a customer and the project manager came
I'm building some custom content types to capture customer data on a website. Admins
I'm building an application that is used by several different customers. Each customer has
I'm looking for some visual statechart-editor, for my customer. I'm building for him server
I am building a customer-facing website that requires me to build 1) some analytics
I'm currently building an web application for a customer that uses a rich client.
We are building a multiuser app that has one database per customer. All customer
I am building a website for a customer who may not be very computer
I am building a product catalog for a customer website under ASP.NET using .NET

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.