简体   繁体   中英

Bootstrap Typeahead.js Ajax call - way to add extra parameters?

I'm using bootstrap typeahead and I have the following code:

Script.js

$('#demo7').typeahead({
            ajax: {
                method: "POST",
                dataType: "JSON",
                url: '@Url.Action("List", "Partials")',
                data: { something: 35 },
                triggerLength: 1 
            },
            scrollBar: true,
            displayField: 'Name'
        });

PartialsController.cs

[HttpPost]
        public JsonResult List(string query, string something)
        {
            try
            {
                return Json(this.GetList());
            }
            catch (Exception ex)
            {
               throw;
            }
        }

And I want to know how can I pass extra parameters to the controller, I try to put data: { something: 35 } in AJAX call but in the controller this parameter is always null... any idea to pass extra parameters? Thank you!

In Option , you can use Source , and then do an ajax call normally. Have a look on this https://gist.github.com/thorst/2960885

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM