Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/84.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
Jquery 将额外参数传递到我的数据\u自动完成\u源_Jquery_Asp.net Mvc_Asp.net Mvc 4_Razor - Fatal编程技术网

Jquery 将额外参数传递到我的数据\u自动完成\u源

Jquery 将额外参数传递到我的数据\u自动完成\u源,jquery,asp.net-mvc,asp.net-mvc-4,razor,Jquery,Asp.net Mvc,Asp.net Mvc 4,Razor,我有以下要求:- 1.具有数据自动完成源的文本框,如下所示:- <input type="radio" name="searchType" value="number" /> number <input type="radio" name="searchType" value="name"/>name $("input[data-autocomplete-source]").each(function () { var target = $(this);

我有以下要求:-

1.具有数据自动完成源的文本框,如下所示:-

<input type="radio" name="searchType" value="number" /> number
<input type="radio" name="searchType" value="name"/>name
$("input[data-autocomplete-source]").each(function () {
        var target = $(this);
        target.autocomplete({ source: target.attr("data-autocomplete-source"), minLength: 2, delay: 2000 });

    });
@Html.TextBoxFor(model=>model.Technology.Search,新建){ data\u autocomplete\u source=Url.Action(“autocomplete”、“Switch”)})

2.两个单选按钮,按名称或编号选择进行自动完成搜索的关键字,如下所示:-

<input type="radio" name="searchType" value="number" /> number
<input type="radio" name="searchType" value="name"/>name
$("input[data-autocomplete-source]").each(function () {
        var target = $(this);
        target.autocomplete({ source: target.attr("data-autocomplete-source"), minLength: 2, delay: 2000 });

    });
编辑 我尝试了以下方法:-

@Html.TextBoxFor(model => model.Technology.Search, new { data_autocomplete_source = Url.Action("AutoComplete", "Switch", new { SearchBy = Model.SearchBy}) })
@Html.RadioButtonFor(a=>a.SearchBy, "number", new { id = "number" })number
@Html.RadioButtonFor(a=>a.SearchBy, "Name", new { id = "name" })Name
但是SearchBy值总是空的


谢谢

您需要传递一个不是来自模型的值,这就是为什么它是
null
。我建议您在JQuery函数中传递参数。 然后它可以使用客户端的参数调用您的操作

 $("#myTextBoxSearch").each(function () {
    var searchByVal = $('input[name=SearchBy]:checked').val();  
    var target = $(this);
    target.autocomplete({ source:@Url.Action("AutoComplete", "Switch", new { SearchBy = searchByVal}) , minLength: 2, delay: 2000 });

 });
如果您认为:

@Html.TextBoxFor(model => model.Technology.Search, new { id="myTextBoxSearch" })
@Html.RadioButtonFor(a=>a.SearchBy, "number", new { id = "number" })number
@Html.RadioButtonFor(a=>a.SearchBy, "Name", new { id = "name" })Name
请注意,您可以使用所需变量的名称。我只是给你指路。 我希望它能帮助你