Pregunta

This works fine:

@(Html.Telerik().DatePicker().Name("FieldName").Value(Model.FieldName))

as does this:

@(Html.Telerik().DatePickerFor(x => x.FieldName)

But I'd like to have a name/id for the control that is different from my data model field name. If I do this:

@(Html.Telerik().DatePicker().Name("DifferentName").Value(Model.FieldName))

then the control is initialized properly from Model.FieldName, but the storage is not bound to it. How can I achieve the desired result?

¿Fue útil?

Solución

Use Telerik's InputHtmlAttributes method to assign a unique ID to the input control:

@(Html.Telerik().DatePickerFor(x => Model.DataField)
    .InputHtmlAttributes(new {id="UniqueID"}))

Note that this is different than HtmlAttributes which affects a wrapper div and not the input control.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top