asp.net mvc - Adding data- attribute to an ASP MVC @Html.RouteLink -


i use javascript library hits data- attribute in link have created.

@model ienumerable<string>   @foreach (var link in model) {     @html.routelink(       link,       new { controller = "product", action = "list", category = link, page = 1 },       new       {           @class = link == viewbag.selectedcategory ? "selected" : null,            id= link.replace(" ","")       }     ) } 

i able add class , id when try add data-filter returns , error

 @class = link == viewbag.selectedcategory ? "selected" : null,        data-filter = link.replace(" ","") 

invalid annonymous type

@class = link == viewbag.selectedcategory ? "selected" : null,    data_filter = link.replace(" ","") 

as d.r. has pointed out, mvc has option of turning underscores in dashes.


Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -