Dropdownlist and HtmlFieldPrefix producing invalid name property when id is set

2 Answers 336 Views
DropDownList
jovaughn
Top achievements
Rank 1
Iron
jovaughn asked on 17 Jan 2022, 05:53 PM | edited on 20 Jan 2022, 12:15 PM
I am attempting to set 

"Html.ViewData.TemplateInfo.HtmlFieldPrefix"

on a partial view to bind elements of a collection back to a view model.

If I set the prefix as well as overriding the id property in the dropdownlist html
the name property seems to have an extra prefix attached

 

See the Demo where the first dropdown has the id set and produces an invalid name.

The second dropdown does not have the id set and the name produced is correct.

Demo

This does not seem to occur when setting the id, prefix, and using the html helpers.

 

2 Answers, 1 is accepted

Sort by
0
Accepted
jovaughn
Top achievements
Rank 1
Iron
answered on 20 Jan 2022, 04:39 PM

I attached an updated project.

Few things to note

  1. I do not believe this issue occurs using the html helpers
  2. The general idea is to have the name in the partial view match the path to the property so that the value is submitted correctly on form submit
  3. As far as I can tell if I explicitly set the id property the name ends up with an extra prefix attached(in red). This does not seem to occur if the id is not set.
  4. I may want to explicitly set the id so that the element(s) can be found easier.
Stoyan
Telerik team
commented on 25 Jan 2022, 02:02 PM

Hi Jovaughn,

Thank you for sending a modified project. Upon closer inspection I observed the reported behavior in the REPL Demo you provided as well. You are on the right track, the correct resolution of the issue is not to set an explicit id to the Components.

The reason for this is that the string passed to the name configuration of the Telerik UI Components is used to also set the Component's id. The issue arises when you combine changing the id set by the name property with a prefix.

You can still change the name to modify the id of the Component. Alternatively, if you like you can add a custom class instead of an id.
    <kendo-dropdownlist name="orders1" style="width:100%"
                        datatextfield="ShipName"
                        datavaluefield="OrderID"
                        min-length="3"
                        template="#= OrderID # | For: #= ShipName #, #= ShipCountry #"
                        height="520"
                        class="123"                        
                        filter="FilterType.Contains">
 Hopefully the information above is useful. Please don't hesitate to let me know should further questions occur.
0
Stoyan
Telerik team
answered on 20 Jan 2022, 01:04 PM

Hi Jovaughn,

Thank you for making the effort to create a Demo REPL.

Unfortunately, I have trouble reproducing the scenario at hand since the REPL doesn't allow modifications to the ViewData sent in the Controller. For this reason could you please modify the attached sample project that implements 2 DropDownList in a similar fashion to recreate the experienced behavior? This will allow me to investigate the issue and suggest a possible solution.

Thank you for your cooperation in advance.

Regards,
Stoyan
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
DropDownList
Asked by
jovaughn
Top achievements
Rank 1
Iron
Answers by
jovaughn
Top achievements
Rank 1
Iron
Stoyan
Telerik team
Share this question
or