Multiselect has undefined instead of table values

1 Answer 90 Views
MultiSelect
Michael
Top achievements
Rank 1
Michael asked on 09 Aug 2024, 03:31 AM

Hello,

I have this code on my index.cshtml:

@(Html.Kendo().MultiSelect()
    .Name("selectedmembers")
    .Placeholder("Please select the members on the job...")
    .DownArrow(true)
    .AutoClose(false)
    .DataTextField("MemberName")
    .DataValueField("MemberId")
    .Filter("contains")
    .DataSource(source =>
    {
        source.Read(read =>
        {
            read.Action("GetPeople", "Combo");
        });
    })
    )

And my GetPeople code looks like this:

public JsonResult GetPeople(string text)
{
    using (var db = new chilternModel())
    {
        var members = db.Members.Select(member => new Member()
        {
            MemberName = member.MemberName,
            MemberId = member.MemberId
        });

        return Json(members.ToList());
    }
}

When I run the code I get undefined as the text value.  The database is a mySql running locally.

I have checked the members variable and it has the appropriate information for a jsonResult to be returned, but the control seems to ignore the text field (and I assume the MemberId as well)

Thanks in advance.

Michael

Michael
Top achievements
Rank 1
commented on 12 Aug 2024, 10:09 PM

Hi Ivaylo,

Thank you for the sample.  As soon as I started looking, I noticed the problem immediately.  I was missing the following line:

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

As soon as I added this, it worked like a charm.

Thanks for all your help.

Michael

1 Answer, 1 is accepted

Sort by
0
Accepted
Ivaylo
Telerik team
answered on 12 Aug 2024, 10:23 AM

Hi Michael,

First, I want to thank you for the code snippet and the details provided. 

I reviewed your code and replicated it in my environment, where the "MultiSelect" component functioned as expected. It correctly displayed the values of the members rather than showing "undefined."

I attached the sample app to this reply. You can try to reproduce it and if the issue persists, please provide more information about your code, and we will try our best to assist you.

I hope this information was helpful.

Regards,
Ivaylo
Progress Telerik

Do you have a stake in the designеr-developer collaboration process? If so, take our survey to share your perspective and become part of this global research. You’ll be among the first to know once the results are out.
-> Start The State of Designer-Developer Collaboration Survey 2024

Tags
MultiSelect
Asked by
Michael
Top achievements
Rank 1
Answers by
Ivaylo
Telerik team
Share this question
or