This is a migrated thread and some comments may be shown as answers.

DropDownLists and Prefixes

7 Answers 339 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
FlexDigital
Top achievements
Rank 1
FlexDigital asked on 18 Apr 2013, 06:29 PM
Hey guys,

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

Sort by
0
Georgi Krustev
Telerik team
answered on 22 Apr 2013, 11:54 AM
Hello Bo,

 
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.

Regards,
Georgi Krustev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Nikki
Top achievements
Rank 1
answered on 09 May 2020, 01:43 AM
Is this still an issue?  I have a kendo dropdownlist control with the name SelectedRecord.StateId and I am trying to set the value in jquery: $('#SelectedRecord.StateId').data('kendoDropDownList').value(10) but am getting errors or the value doesn't get set.  
0
Petar
Telerik team
answered on 12 May 2020, 10:40 AM

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

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
0
Nikki
Top achievements
Rank 1
answered on 12 May 2020, 01:31 PM

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

0
Petar
Telerik team
answered on 14 May 2020, 09:13 AM

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

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
0
Nikki
Top achievements
Rank 1
answered on 14 May 2020, 12:33 PM
Perfect! Working great now.  Thanks so much!
0
Petar
Telerik team
answered on 15 May 2020, 02:56 PM

You are welcome, Nikki!

I am happy that the suggested approach resolved the issue. 

Regards,
Petar
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
Tags
DropDownList
Asked by
FlexDigital
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Nikki
Top achievements
Rank 1
Petar
Telerik team
Share this question
or