0

Disqus wants me to add an attribute called data-disqus-identifier to my links, but for obvious reasons, new { @data-disqus-identifier = "article" } gives me a syntax error.

Any idea what to do in these situations?

Thanks,

Rei

1
  • 2. I wonder if there's less overload hell in 3. Commented Nov 11, 2010 at 4:26

2 Answers 2

4

You can pass a Dictionary<string, object> with arbitrary string keys.
The syntax will be more verbose: new Dictionary<string, object> { { "data-disqus-identifier", "article" } }.

You may want to create an extension method or a static method on a static class with a short name that takes a smaller parameter set and returns the dictionary.

Sign up to request clarification or add additional context in comments.

4 Comments

This doesn't work either, it seems to just try to reflect on the Dictionary... <a comparer="System.Collections.Generic.GenericEqualityComparer1[System.String]" count="1" keys="System.Collections.Generic.Dictionary2+KeyCollection[System.String,System.Object]" values="System.Collections.Generic.Dictionary2+ValueCollection[System.String,System.Object]" >blah</a>`
return helper.ActionLink(linkText, "Details", "Articles", null, null, "disqus-thread", new { year = year, month = month, slug = slug }, new Dictionary<string, object> { { "data-disqus-identifier", "article-" + id } } );
@Rei: Add new RouteValueDictionary(new { ... }) to the second-to-last parameter. (You need to match the overload that takes an IDictionary<string, object> htmlAttributes) You might want to put this into an extension method.
Ahh there we go. Turns out that the IDictionary overload also requires the route values to be given as a RouteValueDictionary as well. Thanks!
0

In MVC 3, if you use underscore _ instead of hyphens - in your property names then MVC will automatically convert them to hyphens in the resulting HTML. So, something like this should work for you:

new { data_disqus_identifier = "article" } 

2 Comments

Are you sure? I don't see that in the source.
Ah, sorry, that's an MVC 3 feature.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.