2011-01-30 3 views
221

TextboxFor를 사용하여 data-* html 속성을 어떻게 추가합니까? Html5 data- * with asp.net mvc TextboxFor html 속성

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

보시다시피

에서, - 여기 data-url 문제를 일으키는 :

내가 현재 가지고있는 것입니다. 이것 주위에 뭐야?

+0

가능한 중복 [하이픈 HTML은 asp.net의 MVC와 속성 (http://stackoverflow.com/questions/2897733/hyphenated-html-attributes-with-asp-net-mvc) –

답변

373

당신은 밑줄 (_)를 사용할 수 있고 도우미가 나머지를 할 수있을만큼 지능 :

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

그리고 할 수있을 미리 ASP.NET MVC 3 버전에서 동일한을 달성하고자하는 사람들을 위해

<%= Html.TextBoxFor(
    model => model.Country.CountryName, 
    new Dictionary<string, object> { 
     { "data-url", Url.Action("CountryContains", "Geo") } 
    } 
) %> 
+6

지정이 동작입니다 어디서나 :)? – Rookian

+0

@Rookian, 어디서나 지정되는지는 잘 모르겠다. 나는 인터넷을 통한 약간의 blog 지위가 그것에 대해 말하는 oughta다고 생각한다. –

+0

'EditorFor'에 대해 작동하지 않습니다 – Ryan