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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T03:28:11+00:00 2026-05-14T03:28:11+00:00

I am trying to use HTML5 data- attributes in my ASP.NET MVC 1 project.

  • 0

I am trying to use HTML5 data- attributes in my ASP.NET MVC 1 project. (I am a C# and ASP.NET MVC newbie.)

 <%= Html.ActionLink("« Previous", "Search",
     new { keyword = Model.Keyword, page = Model.currPage - 1},
     new { @class = "prev", data-details = "Some Details"   })%>

The “data-details” in the above htmlAttributes give the following error:

 CS0746: Invalid anonymous type member declarator. Anonymous type members 
  must be declared with a member assignment, simple name or member access.

It works when I use data_details, but I guess it need to be starting with “data-” as per the spec.

My questions:

  • Is there any way to get this working and use HTML5 data attributes with Html.ActionLink or similar Html helpers ?
  • Is there any other alternative mechanism to attach custom data to an element? This data is to be processed later by JS.
  • 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-14T03:28:12+00:00Added an answer on May 14, 2026 at 3:28 am

    Update: MVC 3 and newer versions have built-in support for this. See JohnnyO’s highly upvoted answer below for recommended solutions.

    I do not think there are any immediate helpers for achieving this, but I do have two ideas for you to try:

    // 1: pass dictionary instead of anonymous object
    <%= Html.ActionLink( "back", "Search",
        new { keyword = Model.Keyword, page = Model.currPage - 1},
        new Dictionary<string,Object> { {"class","prev"}, {"data-details","yada"} } )%>
    
    // 2: pass custom type decorated with descriptor attributes
    public class CustomArgs
    {
        public CustomArgs( string className, string dataDetails ) { ... }
    
        [DisplayName("class")]
        public string Class { get; set; }
        [DisplayName("data-details")]
        public string DataDetails { get; set; }
    }
    
    <%= Html.ActionLink( "back", "Search",
        new { keyword = Model.Keyword, page = Model.currPage - 1},
        new CustomArgs( "prev", "yada" ) )%>
    

    Just ideas, haven’t tested it.

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

Sidebar

Related Questions

I'm new to ASP.NET and MVC in particular. Now, I'm trying to understand if
I'm trying to use jQuery and the HTML5 File API to get data from
I am trying to use XPath to extract some HTML tags and data and
I'm trying to use XSL-stylesheets in order to transform some generated XML-data to HTML-output.
I'm trying to make use of the results attribute of HTML5 <input type=search> tags
I am trying to use the HTML Agility pack to scrape some data from
I'm a newbie to jquery, but am trying to use it in my project.
I'm trying to use html5 validation and ajax. The method checkValidity doesn't solve my
I am trying to use the HTML5 canvas element to draw some arcs and
I am trying to use the HTML5 file API and jQuery to show the

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.