Cannot pass search term as parameter


Eli

I want to display some data in a dropdown list and implement autocomplete. To do this, I use select2a jQuery plugin. My problem is that the search term written in the search box is not being passed as a parameter to my method in the controller. Here is my ajax request:

$('#someId').select2({
        minimumInputLength: 1,
        allowClear: true,

        ajax: {
            url: "/controllerName/methodName",
            dataType: "json",
            type: "GET",
            data: function (params) {

                var queryParameters = {
                    term: params.term

                }
                return queryParameters;

            },

            processResults: function (data) {
                return {
                    results: $.map(data, function (students) {
                        return {
                            text: students.name,
                            id: students.id
                        }
                    })
                };
            }
        }
    });

Here is the html:

<div class="form-group">
<label asp-for="someId" class="col-md-2 control-label"></label>
 <div class="col-md-4">
<select asp-for="someId"  class="form-control" style="display:table-cell; 
 width:100%"></select>
 </div>
 </div>

This is my method in the controller:

[HttpGet]
        public IActionResult GetStudents(string searchTerm)
    {
        //some code
    }

Is there something wrong with my Ajax request?

Adaimori

You are sending a variable called "term" as your search parameter. But your controller needs a variable called "searchTerm".

The variable names need to match, otherwise how does the controller know what to pick from the query string?

Especially consider the very common case of sending multiple parameters from the browser. At this point, the naming convention is critical, so the correct parameters match the correct variables in the controller method.

Related


Pass "" as parameter in text search

royal dad This seems simple enough and I'm stuck. I have a function in VBA that searches a string and replaces a character with another character (sort of like the REPLACE function, but with some other functions in it) I call the function like this: NewText =

Pass "" as parameter in text search

royal dad This seems simple enough and I'm stuck. I have a function in VBA that searches a string and replaces a character with another character (sort of like the REPLACE function, but with some other functions in it) I call the function like this: NewText =

Solr - Cannot search when term ends with "y"

Brazil This question seems really ridiculous. I always get 0 results when searching for entries ending in "y". I know they exist. 0 result: Brazil Tony Marcy x result: Bart yours maximum With the last three I get the desired result ( Barthy B, Tony Banderas, M

cannot pass char *** as parameter

Bisla It's easy to see the tasks to be done here. Read a list of files and pass it to another function. Why doesn't this work. When I try to store the filename in a local char** it works fine, but I can't send it back via a pointer. gives segmentation fault. i

cannot pass char *** as parameter

Bisla It's easy to see the tasks to be done here. Read a list of files and pass it to another function. Why doesn't this work. When I try to store the filename in a local char** it works fine, but I can't send it back via a pointer. gives segmentation fault. i

Firebase Analytic Search_Term parameter value not showing

LKH I want to log user search events to Firebase, but the Search_Term parameter value in the search events is not showing on the dashboard. Here is my code: Bundle bundle = new Bundle(); bundle.putString(FirebaseAnalytics.Param.SEARCH_TERM, sea

cannot pass string parameter to api

Mehdi Sgh: I created function in spring: @GetMapping("/projets/traitement/{ville}") public ResponseEntity<List<Projet>> getProjectsInTraitement(String ville) { log.debug("REST request to get a page of Projets"); List<Projet> page = projetRe

Cannot pass state parameter to mutation

rebirth I read the documentation about it, but there are still some problems Apollo graphql clientwith combining Apolloand react. Consider, we have a simple form with 4 fields with a submit button. After pressing submit, the value in the field will be saved to

cannot pass parameter 1 by reference

Zorono So I'm trying to check if the value of the variable is equal to the last row of the array, if($ver == end(Self::Supported_Version) {}but it results in Cannot Pass Parameter 1 by referencean error... my code: namespace John; class SP { const Supported_

cannot pass string parameter to api

Mehdi Sgh: I created function in spring: @GetMapping("/projets/traitement/{ville}") public ResponseEntity<List<Projet>> getProjectsInTraitement(String ville) { log.debug("REST request to get a page of Projets"); List<Projet> page = projetRe

Cannot pass class as parameter to command

Kitten I'm new to programming and I have my pass class that I created with difficulty <Window.Resources>as XAMLa parameter to a command. <Window.Resources> <local:RegisterWindowViewModel x:Key="RegViewModel"/> <local:RegisterValidationConverter x

Cannot pass state parameter to mutation

rebirth I read the documentation about it, but there are still some problems Apollo graphql clientwith combining Apolloand react. Consider, we have a simple form with 4 fields with a submit button. After pressing submit, the value in the field will be saved to

cannot pass parameter 1 by reference

Zorono So I'm trying to check if the value of the variable is equal to the last row of the array, if($ver == end(Self::Supported_Version) {}but it results in Cannot Pass Parameter 1 by referencean error... my code: namespace John; class SP { const Supported_

Cannot pass state parameter to mutation

rebirth I read the documentation about it, but there are still some problems Apollo graphql clientwith combining Apolloand react. Consider, we have a simple form with 4 fields with a submit button. After pressing submit, the value in the field will be saved to

Cannot pass state parameter to mutation

rebirth I read the documentation about it, but there are still some problems Apollo graphql clientwith combining Apolloand react. Consider, we have a simple form with 4 fields with a submit button. After pressing submit, the value in the field will be saved to

cannot pass parameter 1 by reference

Zorono So I'm trying to check if the value of the variable is equal to the last row of the array, if($ver == end(Self::Supported_Version) {}but it results in Cannot Pass Parameter 1 by referencean error... my code: namespace John; class SP { const Supported_

cannot pass parameter 1 by reference

Zorono So I'm trying to check if the value of the variable is equal to the last row of the array, if($ver == end(Self::Supported_Version) {}but it results in Cannot Pass Parameter 1 by referencean error... my code: namespace John; class SP { const Supported_

cannot pass parameter 1 by reference

Zorono So I'm trying to check if the value of the variable is equal to the last row of the array, if($ver == end(Self::Supported_Version) {}but it results in Cannot Pass Parameter 1 by referencean error... my code: namespace John; class SP { const Supported_

cannot pass parameter 1 by reference

Zorono So I'm trying to check if the value of the variable is equal to the last row of the array, if($ver == end(Self::Supported_Version) {}but it results in Cannot Pass Parameter 1 by referencean error... my code: namespace John; class SP { const Supported_

cannot pass parameter 1 by reference

Zorono So I'm trying to check if the value of the variable is equal to the last row of the array, if($ver == end(Self::Supported_Version) {}but it results in Cannot Pass Parameter 1 by referencean error... my code: namespace John; class SP { const Supported_

cannot pass parameter 2 by reference

username Code: final class SimpleEventManager { private $listeners = array(); public function listen($event, $callable) { $this->listeners[$event][] = $callable; } public function fire($event, array $arguments = array()) { for

cannot pass parameter 2 by reference

username Code: final class SimpleEventManager { private $listeners = array(); public function listen($event, $callable) { $this->listeners[$event][] = $callable; } public function fire($event, array $arguments = array()) { for

Cannot pass parameter by reference - MySQLi

ramp I have a problem with my insert query. I am trying to get the user id from a session variable and insert it into a table along with other variables entered through the form. I tried printing the $userid variable and it showed 1, which is correct. The bind

cannot pass parameter 1 by reference

Zorono So I'm trying to check if the value of the variable is equal to the last row of the array, if($ver == end(Self::Supported_Version) {}but it results in Cannot Pass Parameter 1 by referencean error... my code: namespace John; class SP { const Supported_

cannot pass string parameter to api

Mehdi Sgh: I created function in spring: @GetMapping("/projets/traitement/{ville}") public ResponseEntity<List<Projet>> getProjectsInTraitement(String ville) { log.debug("REST request to get a page of Projets"); List<Projet> page = projetRe

Cannot pass state parameter to mutation

rebirth I read the documentation about it, but there are still some problems Apollo graphql clientwith combining Apolloand react. Consider, we have a simple form with 4 fields with a submit button. After pressing submit, the value in the field will be saved to

Cannot pass state parameter to mutation

rebirth I read the documentation about it, but there are still some problems Apollo graphql clientwith combining Apolloand react. Consider, we have a simple form with 4 fields with a submit button. After pressing submit, the value in the field will be saved to

Cannot pass state parameter to mutation

rebirth I read the documentation about it, but there are still some problems Apollo graphql clientwith combining Apolloand react. Consider, we have a simple form with 4 fields with a submit button. After pressing submit, the value in the field will be saved to

cannot pass parameter 1 by reference

Zorono So I'm trying to check if the value of the variable is equal to the last row of the array, if($ver == end(Self::Supported_Version) {}but it results in Cannot Pass Parameter 1 by referencean error... my code: namespace John; class SP { const Supported_