Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/68.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 ASP.NET MVC自动完成-依赖多个输入字段_Jquery_Asp.net Mvc_Autocomplete - Fatal编程技术网

Jquery ASP.NET MVC自动完成-依赖多个输入字段

Jquery ASP.NET MVC自动完成-依赖多个输入字段,jquery,asp.net-mvc,autocomplete,Jquery,Asp.net Mvc,Autocomplete,我有jquery自动完成功能。i、 e.i输入一个字段,然后根据字段中输入的字符串返回数据。我的问题是,在确定应该返回当前字段的内容时,我还希望使用另一个字段中键入的数据。例如,我只想返回属于某个公司的驱动程序。此数据输入到另一个字段中。如何修改下面的代码以执行此任务?假设我有一个模型。公司财产 查看其中的一部分: <%= Html.AutoCompleteTextBox2("DrvId", "DriverID", Model.DrvId, new { style = "width:200

我有jquery自动完成功能。i、 e.i输入一个字段,然后根据字段中输入的字符串返回数据。我的问题是,在确定应该返回当前字段的内容时,我还希望使用另一个字段中键入的数据。例如,我只想返回属于某个公司的驱动程序。此数据输入到另一个字段中。如何修改下面的代码以执行此任务?假设我有一个模型。公司财产

查看其中的一部分:

<%= Html.AutoCompleteTextBox2("DrvId", "DriverID", Model.DrvId, new { style = "width:200px;" })%>           


<%= Html.InitializeAutoComplete2("DrvId", "DriverID", "Driver ID", Model.DrCmpId, Url.Action("Drivers", "AutoComplete"), new { delay = 100, minChars = 1 }, true)%>
控制器:

public ActionResult Drivers(string q)
    {

        List<TmwXref> driverList = baseService.GetTypeList("Driver");

        for (var i = 0; i < driverList.Count; i++)
        {
            if (driverList[i].Value.StartsWith(q, StringComparison.OrdinalIgnoreCase))
            {
                Response.Output.Write("{0}|{1}\r\n", driverList[i].Value + " - " + driverList[i].Description, i);
            }
        }

        return new CancelViewResult();

    }
用户界面帮助程序:

public static string InitializeAutoComplete2<T>(this HtmlHelper<T> html,
                     string textBoxName, string fieldName, string labelName, string fieldDesc, 
                     string url, object options, bool wrapInReady)
    {

        StringBuilder sb = new StringBuilder();
        if (wrapInReady) sb.AppendLineFormat("<script language='javascript'>");

        if (wrapInReady) sb.AppendLineFormat("$().ready(function() {{");
        sb.AppendLine();
        sb.AppendLineFormat("   $('#{0}').autocomplete('{1}', {{", textBoxName.Replace(".", "\\\\."), url);

        PropertyInfo[] properties = options.GetType().GetProperties();

        for (int i = 0; i < properties.Length; i++)
        {
            sb.AppendLineFormat("   {0} : {1}{2}",
                                    properties[i].Name,
                                    properties[i].GetValue(options, null),
                                    i != properties.Length - 1 ? "," : "");
        }
        sb.AppendLineFormat("   }});");
        sb.AppendLine();
        sb.AppendLineFormat("   $('#{0}').result(function(e, d, f) {{", textBoxName.Replace(".", "\\\\."));
        sb.AppendLineFormat("       $('#{0}').val(d[1]);", fieldName);
        sb.AppendLineFormat("    }});");
        sb.AppendLine();
        if (wrapInReady) sb.AppendLineFormat("}});");
        if (wrapInReady) sb.AppendLineFormat("</script>");
        return sb.ToString();

    }

    public static string AutoCompleteTextBox2<T>(this HtmlHelper<T> html, string textBoxName, string fieldName, string value, object htmlAttributes)
    {

        return string.Format("{0} {1}", html.TextBox(textBoxName, value, htmlAttributes), html.Hidden(fieldName));
    }

第二个数据输入字段也是自动完成字段,还是包含公司列表的下拉列表

我不确定TmwXref对象是什么样子的,但我确定您可以通过某种方式将驱动程序与公司联系起来

如果只是一个下拉列表来选择要筛选的公司,您可能只需执行以下操作:

public ActionResult Drivers(string q)
{
    var company = GetSelectedCompanyHere();

    List<TmwXref> driverList = baseService.GetTypeList("Driver");

    for (var i = 0; i < driverList.Count; i++)
    {
        if (driverList[i].Company == company && driverList[i].Value.StartsWith(q, StringComparison.OrdinalIgnoreCase))
        {
            Response.Output.Write("{0}|{1}\r\n", driverList[i].Value + " - " + driverList[i].Description, i);
        }
    }

    return new CancelViewResult();
}