<script type="text/x-kendo-template" id="contacttemplate">
<div>
@(Html.Kendo().DropDownListFor(m=>m.SelectedContactAddressId)
.Name("addressDropDown")
.DataTextField("FullStreetAddress")
.DataValueField("ContactAddressId")
//.BindTo(#:ContactAddresses#) // Normally non template .BindTo(Model.ContactAddresses) This is a error also
.ToClientTemplate()
)
6 Answers, 1 is accepted

@(Html.Kendo().DropDownList()
.Name("addressDropDown")
.DataTextField("FullStreetAddress")
.DataValueField("ContactAddressId")
//.BindTo("#:ContactAddresses#")
.ToClientTemplate()
)
Hello Carlos,
If the model is declared like this:
@model MyApp.Models.ContactViewModel
You will have access to the ContentAddresses field:
.BindTo(Model.ContactAddresses)
However, if you are using an IEnumerable of ContactViewModel:
@model IEnumerable<MyApp.Models.ContactViewModel>
you cannot use this approach since the model will be a collection of ContactViewModel.
Evaluating the ContactAddresses field in the template ("#:ContactAddresses#") won't work either since when using server binding (BindTo) the data must already be present on the client. BindTo works with the model directly, e.g.: Model.ContactAddresses, or you can pass a server variable, for instance a ViewBag:
.BindTo((System.Collections.IEnumerable)ViewData["addresses"])
Thus, in this scenario consider using remote binding, instead of server binding with the BindTo method.
Regards,
Ivan Danchev
Progress Telerik


I have had some time to research to add remote binding. My problem is the Id/Name is not unique and I can not pass a parameter. The following code creates an invalid template:
@(Html.Kendo().DropDownList()
.Name("homePhoneDropdown_#:ContactId#")
.DataTextField("PhoneNumber")
.DataValueField("ContactPhoneId")
.DataSource(source =>source
.Ajax()
.Read(read => read.Action("ReadPhone", "Summary", new { Area = "Summary", id = #:ContactId# }))
)
.HtmlAttributes(new { style = "width: 100%;", @class="dropdown" })
.ToClientTemplate()
)
I need to pass the current ContactId to get the correct phones numbers from the service. I have tried a literal 7522, #:ContactId#, #=ContactId# with and without quotes. I am not sure were the error is in the ID or the read. Any help would be appreciated.

