MultiSelectFor should behave like a DropDownListFor

1 Answer 35 Views
MultiSelect
Alex
Top achievements
Rank 1
Alexasked on25 Nov 2022,01:57 PM

Hello,

I have following MultiSelectFor:


@(Html.Kendo().MultiSelectFor(x => x.TitleAttachmentForm.AuthorsList) .AutoBind(true) .DataTextField("SearchValue") .DownArrow() .DataValueField("Id") .DataSource (ds=> ds .Custom() .Transport(transport => transport .Read(r => r .Url("?handler=AuthorPublisherRead").Data("authorDataFunction") )) .ServerFiltering(true) ) .Filter(FilterType.StartsWith) .Height(400) .ItemTemplate("#= (data.Title == null) ? '' : data.Title # #: data.Firstname # #: data.Lastname #

#: data.SubDisplayValue #

"
) .TagTemplate("#= (data.Title == null) ? '' : data.Title # #: data.Firstname # #: data.Lastname #") )


The MultiSelectFor is binded to following remote api:

public async Task<JsonResult>OnGetAuthorPublisherRead([CanBeNull] string filterValue, [CanBeNull] string bindedvalue)

{ //Deleted }

This is used to filter for items on the remote site and get the binded value.

In my DropDownListFor I can use authorDataFunction to receive the value and the text of my DropDown:


函数authorDataFunction() { return { __RequestVerificationToken: kendo.antiForgeryTokens().__RequestVerificationToken, filterValue: $("#mydropdown").getKendoDropDownList().filterInput.val(), bindedvalue: $("#mydropdown").getKendoDropDownList().value() }; }

I played around with the api, however, I am not able to receive the input text and value(s):


函数authorDataFunction() { var multiselect = $("#TitleAttachmentForm_AuthorsList").data("kendoMultiSelect"); return { __RequestVerificationToken: kendo.antiForgeryTokens().__RequestVerificationToken, filterValue: multiselect.filterInput.val(), bindedvalue:multiselect.value() }; }

Its telling me, that filterInput is undefined. also multiselect.text() does not work.

How can I access the binded value and the input in the .net core component?

1 Answer, 1 is accepted

Sort by
0
Accepted
Aleksandar
Telerik team
answered on30 Nov 2022,07:28 AM

Hello Alex,

The MultiSelect provides reference to theinput fieldof the component. You can use it to get the value of the user input. Thevalue methodwill return the values of the selected dataItems, as defined via the DataValueField.

函数authorDataFunction(){varmultiselect = $("#products").data("kendoMultiSelect");return{__RequestVerificationToken: kendo.antiForgeryTokens().__RequestVerificationToken,filterValue: multiselect.input.val(),bindedvalue:multiselect.value() }; }

Check this REPL example for a demonstration of the above.如果你检查the network tab as you type you will note the data for the user input being sent and the already selected items as well.

The DropDownList does not provide an option for free text entry and thus when filtering is enabled an additional input is rendered, thus the filterInput field is available.

I hope this helps.

Regards,
Aleksandar
Progress Telerik

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

Tags
MultiSelect
Asked by
Alex
Top achievements
Rank 1
Answers by
Aleksandar
Telerik team
Share this question
or
Baidu
map