I'm using a standard MVC Kendo DropDownList on a partial view.
I have a ViewData.TemplateInfo.HtmlFieldPrefix set
The problem is that the initial value that is set in the model doesn't get transferred to the dropdown when it is rendered. As soon as I take away the prefix it works fine.
@(Html.Kendo().DropDownListFor(o => o.CCInfo.CCExpireMonth)
.DataValueField("Value")
.DataTextField("Text")
.Animation(false)
.Height(150)
.BindTo(Model.CCInfo.CCExpireMonthList)
)
At the suggestion of a few other posts here I've found that I can set .Value() explicitly to set the value.
Using .Name() also allows the initial value to be set if I set it to "CCInfo.CCExpireMonth" rather than with the prefix (apart from the fact that now it doesn't have a prefix so it doesn't play nice with the rest of my form)
Note: This does not affect the actual javascript version, only the MVC wrapper. In fact even copy/pasting the output from the MVC wrapper (input & script tags) directly into the html (albeit, having to set the prefix into the id/name explicitly), makes it work as expected.
I know I can use these solutions, but I was wondering if there was any sort of fix or update coming up for this bug.
Edit: I should also note that I am using the latest update (v2013.1.319)
7 Answers, 1 is accepted
There is a known issue related with BindTo method and set value. I will suggest you download the latest internal build and give it a try. Let me know if the problem still persists.
Georgi Krustev
the Telerik team
Hi Nikki,
To be able to help you with the current thread, I will need more details about the DropDownList's definition and the context in which it is used. Can you send me the DropDownList's definition? Can you share the errors that you get? When the shared code line is executed?
The best approach for resolving your issue will be to submit a support ticket with a runnable project in which the reported behavior can be reproduced. Thus will be able to debug the project and provide feedback about it.
Regards,
Petar
Progress Telerik
Our thoughts here at Progress are with those affected by the outbreak.
Thanks Petar.
My dropdownlist definition is:
<kendo-dropdownlist name="SelectedRecord.StateId" bind-to="ViewBag.StateId" Auto-Width="true" option-label=" "></kendo-dropdownlist>
In the controller, I have this:
ViewData["StateId"] = new SelectList(_stateCodes, "StateId", "StateTitle", model.SelectedRecord.StateId);
These are populated fine except when trying to populate them client side using jquery. I have this code which runs once I click a button to select the state I want (from a list of states in a kendo grid):
function addressSelect(e) {
var dataItem = this.dataItem($(e.currentTarget).closest("tr"));
$('#SelectedRecord.StateId').data('kendoDropDownList').value(dataItem.StateId);
}
I am getting this error: "TypeError: Cannot read property 'value' of undefined". I have tried setting the value multiple ways without success:
$('#SelectedRecord.StateId').val(dataItem.StateId); -- this does nothing
$('#SelectedRecord_StateId').val(dataItem.StateId); -- this does nothing
$('#SelectedRecord_StateId').data('kendoDropDownList').value(dataItem.StateId); -- i get the same error
Hi Nikki,
Thank you for the additional details. I would assume that the issue is triggered by the dot in the ID of the DropDownList. Try escaping the dot symbol with the following definition:
$('#SelectedRecord\\.StateId').data('kendoDropDownList').value(dataItem.StateId);
Adding the marked in yellow backslashes should resolve the case.
Let me know if the issue continues to exist after applying the above.
Regards,
Petar
Progress Telerik
Our thoughts here at Progress are with those affected by the outbreak.
You are welcome, Nikki!
I am happy that the suggested approach resolved the issue.
Regards,
Petar
Progress Telerik
Our thoughts here at Progress are with those affected by the outbreak.