Completed
Last Updated: 20 Dec 2024 10:53 by ADMIN
Release 2025 Q1 (Feb)
Mike
Created on: 29 Nov 2024 11:01
Category: DropDownList
Type: Bug Report
1
Adding attributes and classes in TagHelper DropDownList causes NullReferenceException when runtime compilation is enabled

### Bug report

When the project is configured for runtime compilation, and the TagHelper DropDownList has custom classes or attributes, NullReferenceException is thrown.

### Reproduction of the problem

1. Create a .NET 8 project and install the  Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation NuGet package.

2. Define a TagHelper DropDownList and add a custom class:

//Program.cs
builder.Services.AddControllersWithViews().AddRazorRuntimeCompilation();

builder.Services.AddMvc().AddJsonOptions(options => options.JsonSerializerOptions.PropertyNamingPolicy = null);
builder.Services.AddKendo();

//View

<kendo-dropdownlist for="Id" datatextfield="Text" datavaluefield="Value" auto-width="true" class="form-control w-75">
    <datasource type="Kendo.Mvc.UI.DataSourceTagHelperType.Ajax">
        <transport>
            <read url="@Url.Action("GetData", "Home")"/>
        </transport>
    </datasource>
</kendo-dropdownlist>

3. Run the application and observe the exception: "NullReferenceException: Object reference not set to an instance of an object."

4. When using the HtmlHelper version of the DropDownList or removing the custom class from the TagHelper declaration, the error does not occur.

### Expected/desired behavior

The TagHelper DropDownList must exhibit the same behavior as the HtmlHelper DropDownList.

### Workaround

Add the custom class with jQuery:

<kendo-dropdownlist for="Id" datatextfield="Name"  datavaluefield="Id"  auto-width="true">
 ...
</kendo-dropdownlist>

<script>
$(document).ready(function(){
    $("#Id").addClass("form-control w-75"); // add the class to the hidden input element
    $("#Id").attr("required", "required");
    $("#Id").closest("span.k-dropdownlist").addClass("form-control w-75"); // add the class to the wrapper element
});
</script>

Alternatively, switch to the HtmlHelper version of the DropDownList.

### Environment

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

2 comments
ADMIN
Mihaela
Posted on: 20 Dec 2024 10:53

Hi Mike, 

I completely understand your concerns and expectations and forwarded your feedback to our team.

The fix will be available in the upcoming release in February (2025 Q1).

Thank you for your understanding regarding the matter.

Regards,
Mihaela
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.

Mike
Posted on: 13 Dec 2024 15:06
Considering this is basically a hard fail if the control exists on a page, I would have expected a faster or point release to address the bug, not have it as part of a general release.