1

I have a requirement to add a data- attribute to a Kendo DataPicker object.

However, I do not see an intuitive way to do it. There's only 'name' and 'htmlattributes' which only appears to accept 'style', 'title', and 'id'.

I need this for jQuery operations so there is no other way around it.

Here's what I have so far:

<div>
@(Model.FieldLabel): @(Html.Kendo().DatePicker()
    .Name("valueToGet")
    .Value(Model.FieldValue)
    .HtmlAttributes(new { style = "width: 100%", title = Model.FieldLabel, id = Model.FieldId.ToString()})
    .Deferred()        
    )
</div>
Beau D'Amore
  • 3,174
  • 5
  • 24
  • 56

1 Answers1

6

You need to replace dashes (-) with underscores (_), the compiler will convert it appropriately.

<div>
@(Model.FieldLabel): @(Html.Kendo().DatePicker()
    .Name("valueToGet")
    .Value(Model.FieldValue)
    .HtmlAttributes(new { style = "width: 100%", title = Model.FieldLabel, id = Model.FieldId.ToString(), data_test = "Test Value"})
    .Deferred()        
    )
</div>
Adrian
  • 8,271
  • 2
  • 26
  • 43