Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# ASP.NET/Ajax-如何在调用中传递参数?_C#_Jquery_Asp.net_Sql_Ajax - Fatal编程技术网

C# ASP.NET/Ajax-如何在调用中传递参数?

C# ASP.NET/Ajax-如何在调用中传递参数?,c#,jquery,asp.net,sql,ajax,C#,Jquery,Asp.net,Sql,Ajax,我试图过滤我的结果,但不知道如何设置ajax查询,使其与select2下拉列表正常工作。据我所知,你应该使用数据,但这不仅仅是传递值和过滤我的呼叫 以下是我的ajax: $('#e1').select2({ placeholder: "Select an ingredient...", minimumInputLength: 2, ajax: {

我试图过滤我的结果,但不知道如何设置ajax查询,使其与select2下拉列表正常工作。据我所知,你应该使用数据,但这不仅仅是传递值和过滤我的呼叫

以下是我的ajax:

            $('#e1').select2({
                placeholder: "Select an ingredient...",
                minimumInputLength: 2,
                ajax: {
                    url: "../api/IngredientChoices",
                    data: 'mi',
                    dataType: "json",
                    quietMillis: 500,
                    data: function (term, page) {
                        return {
                            q: term,
                            page_limit: 10,
                            page: page

                        };
                    },
                    results: function (data, page) {
                        var more = (page * 10) < data.length;
                        console.log(more);
                        console.log(data);
                        return { results: data, more: more };

                    },
                    formatResult: function (post) {
                        markup = '<strong>' + post.text + '</strong>';
                    }
                }
            });
这是我的控制器:

    public List<Models.IngredientChoices> Get(string param)
    {
        var choices = (from i in _context.IngredientItems_View(param)

                       select new Models.IngredientChoices
                       {
                           id = i.ItemID,
                           text = i.ConcatName,
                       });
        return choices.ToList();
    }

ajax调用当前返回所有值。

您有一个重复的成员数据:在ajax上-您应该只有一个

编辑:只是一个小东西,但也许你需要一个类:

class myparam {
  string q ;
  int page_limit;
  int page;
}
//decorate for JSON
public List<Models.IngredientChoices> Get(myparm param)
{
    var choices = (from i in _context.IngredientItems_View(param.q)

正如@jmordyk所说,答案是我的q:term与我在c中的参数不匹配。我改变了这一行:

public List<Models.IngredientChoices> Get(string param)
将是:

public List<Models.IngredientChoices> Get(string q)

我相信他们会的,你在哪里看到了这个问题?url:../api/IngreditChoices所期望的数据形式是什么?默认情况?”application/x-www-form-urlencoded;charset=UTF-8'请忽略我将其放入测试中,但代码在删除后仍然不起作用。这或控制器方法中的参数名称需要对作为数据从AJAX函数发送的变量名称进行马赫运算,以便模型绑定器工作。您是对的@jmoerdyk-我需要将c中的参数更改为q,并且工作。