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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T04:49:25+00:00 2026-05-31T04:49:25+00:00

I use a custom extension for my ActionLinks. I have added an attribute data_url

  • 0

I use a custom extension for my ActionLinks. I have added an attribute data_url which is meant to be translated to an attribute of data-url. This is, replacing the underscaore with a dash.

Here is link 1 using my custom extension:

@Ajax.ActionLink("Add", MyRoutes.GetAdd(), new AjaxOptions()
    , new { data_url = Url.Action(...)})

Result: data_url

Here is link 2 using the framework ActionLink:

@Ajax.ActionLink("Add 2", "x", "x", null, new AjaxOptions()
    , new { data_url = Url.Action(...) })

Result: data-url

Here is the extension, simple enough, except that the only way to pass the htmlAttributes through that I know of is by using the ToDictionaryR() extension. I suspect this is the problem, so I am wondering if I should be using something else. I have supplied that extension below too.

public static MvcHtmlString ActionLink(this AjaxHelper helper, string linkText
        , RouteValueDictionary routeValues, AjaxOptions ajaxOptions
        , object htmlAttributes = null)
{
    return helper.ActionLink(linkText, routeValues["Action"].ToString()
        , routeValues["Controller"].ToString(), routeValues, ajaxOptions
        , (htmlAttributes == null ? null : htmlAttributes.ToDictionaryR()));
}

public static IDictionary<string, object> ToDictionaryR(this object obj)
{
    return TurnObjectIntoDictionary(obj);
}
public static IDictionary<string, object> TurnObjectIntoDictionary(object data)
{
    var attr = BindingFlags.Public | BindingFlags.Instance;
    var dict = new Dictionary<string, object>();
    foreach (var property in data.GetType().GetProperties(attr))
    {
        if (property.CanRead)
        {
            dict.Add(property.Name, property.GetValue(data, null));
        }
    }
    return dict;
}

thank you

  • 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-31T04:49:26+00:00Added an answer on May 31, 2026 at 4:49 am

    You could use the AnonymousObjectToHtmlAttributes method which does exactly what you want and you don’t need any custom extension methods:

    public static MvcHtmlString ActionLink(
        this AjaxHelper helper, 
        string linkText, 
        RouteValueDictionary routeValues, 
        AjaxOptions ajaxOptions, 
        object htmlAttributes = null
    )
    {
        return helper.ActionLink(
            linkText,    
            routeValues["Action"].ToString(), 
            routeValues["Controller"].ToString(), 
            routeValues, 
            ajaxOptions, 
            htmlAttributes == null ? null : HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes)
        );
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have run into this problem: Custom Methods & Extension Methods cannot be translated
I have defined a custom html attribute data-something-something. In my view I use an
I want to use Custom URL Scheme to transfer data from application to other
Ok, I am attempting to use this custom extension to perform an entity update.
i have a custom behavior extension which i'm using in my client side app.config
I'm trying to use CFBundleDocumentTypes to associate a custom file extension with my application.
I've got a working custom markup extension which retrieves information out of the DataContext
I have written a custom dialog (form) that I can use in a C#
I want to use custom extension on my web site. I mean, I do
How would you tackle this problem: I have data in my data store. Each

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.