Html5 data-* with asp.net mvc TextboxFor html attributes

前端 未结 1 1572
你的背包
你的背包 2020-11-28 22:15

How do I add data-* html attributes using TextboxFor?

This is what I currently have:

@Html.TextBoxFor(model => model.Country.CountryN         


        
相关标签:
1条回答
  • 2020-11-28 22:22

    You could use underscore (_) and the helper is intelligent enough to do the rest:

    @Html.TextBoxFor(
        model => model.Country.CountryName, 
        new { data_url = Url.Action("CountryContains", "Geo") }
    )
    

    And for those who want to achieve the same in pre ASP.NET MVC 3 versions they could:

    <%= Html.TextBoxFor(
        model => model.Country.CountryName, 
        new Dictionary<string, object> { 
            { "data-url", Url.Action("CountryContains", "Geo") } 
        }
    ) %>
    
    0 讨论(0)
提交回复
热议问题