Completed
Last Updated: 30 Oct 2024 07:18 by ADMIN
Release 2024 Q4 (Nov)
Kaya
Created on: 30 Sep 2024 13:18
Category: MultiSelect
Type: Bug Report
1
MultiSelect TagHelper has incorrect "name" attribute when its "id" attribute is changed

### Bug report

When using the @Html.EditorFor(m => m) configuration to initialize a MultiSelect TagHelper editor, and passing a specified value for its "id" attribute, the "name" attribute of the <select> element contains a prefix.

### Reproduction of the problem

1. Set the MultiSelect TagHelper as an editor editor of a specified Model property and set the "id" attribute using ViewData:

//Model
[UIHint("CustomMultiSelect")]
public IEnumerable<string> Names { get; set; }

//~.Views/Shared/EditorTemplates/CustomMultiSelect.cshtml
@model IEnumerable<string>
@{
    var id = ViewData["id"]?.ToString();
}
<kendo-multiselect for="@Model" placeholder="some custom behavior" bind-to='ViewData["Data"] as List<string>' id='@id'></kendo-multiselect>

2. Define @Html.EditorFor(a=>a.Names, new{id="customId"}) in a form:

@model MyModel

<form id="myForm" data-method="POST"  asp-action="Save" asp-controller="Home"  class="k-form k-form-md">
    <div class="k-form-layout k-d-grid">
        <div class="k-form-field">
            @Html.EditorFor(a=>a.Names, new{id="customId"})
        </div>
    </div>
    ...
</form>

3. When the MultiSelect is loaded, its "name" attribute is "Names.Names" rather than "Names":

When using the HtmlHelper version of the MultiSelect, the "name" attribute is correct:

//~.Views/Shared/EditorTemplates/CustomMultiSelect.cshtml
@model IEnumerable<string>
@{
    var id = ViewData["id"]?.ToString();
}
@(Html.Kendo().MultiSelectFor(m => m)
  .Placeholder("some custom behavior")
  .BindTo((List<string>)ViewData["Data"])
  .HtmlAttributes(new { id = @id })
)

### Expected/desired behavior

When using the @Html.EditorFor(m => m) configuration, the "name" attribute of the MultiSelect TagHelper must match the Model property name when the "id" attribute is set to a custom value.

### Environment

* **Telerik UI for ASP.NET Core version: 2024.3.806
* **Browser: [all]

0 comments