Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/299.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/78.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# mvc4中的级联文本框?_C#_Jquery_Ajax_Asp.net Mvc 4 - Fatal编程技术网

C# mvc4中的级联文本框?

C# mvc4中的级联文本框?,c#,jquery,ajax,asp.net-mvc-4,C#,Jquery,Ajax,Asp.net Mvc 4,您好,我的视图中有两个字段CustomerName和ContactPerson。之前我把这两个字段作为下拉字段。现在,我将customer name字段更改为autoComplete文本框,将contact person字段更改为下拉字段 在此之前,我将这两个字段保留为层叠下拉列表字段。也就是说,如果我选择客户姓名,则与客户姓名相关的联系人将自动出现在联系人下拉列表中 现在我将customer name字段更改为textbox,contact person字段更改为下拉列表。现在我想要的是,如果

您好,我的视图中有两个字段CustomerNameContactPerson。之前我把这两个字段作为下拉字段。现在,我将customer name字段更改为autoComplete文本框,将contact person字段更改为下拉字段

在此之前,我将这两个字段保留为层叠下拉列表字段。也就是说,如果我选择客户姓名,则与客户姓名相关的联系人将自动出现在联系人下拉列表中

现在我将customer name字段更改为textbox,contact person字段更改为下拉列表。现在我想要的是,如果我在CustomerName文本框中键入并选择CustomerName,则与CustomerName相关的联系人必须在ContactPerson下拉列表中自动加载

我的模型(访问者查看模型)

我的Jquery代码

<link href="~/Areas/Sales/Content/themes/base/jquery-ui.css" rel="stylesheet" />
<script src="~/Areas/Sales/Scripts/jquery-2.2.3.min.js"></script>
<script src="~/Areas/Sales/Scripts/jquery-ui.1.10.4min.js"></script>
<script type="text/javascript">

    $(document).ready(function () {
      debugger;
    $("#CustomerName").autocomplete({
      source: function (request, response) {
      $.ajax({
      url: '@Url.Action("GetVisitCustomer", "VisitorsForm")',
      datatype: "json",
      data: {
              Areas: 'Sales',
              term: request.term
            },
     success: function (data) {
     response($.map(data, function (val, item) {
     debugger;
              return {
                           label: val.Name,
                           value: val.Name,
                           customerId: val.ID
                     }                                     
                 }))
                }
             })
          },
   select: function (event, ui) {
   $("#CustomerID").val(ui.item.customerId);
      debugger;
         }
       });
     });


  var Customerid = $("CustomerID").val();
        $('#CustomerName').blur(function () {
            debugger;
            $('#CustomerContactID').empty();
            $.ajax(
                    '@Url.Action("GetContactPersobByCustomerId", "VisitorsForm", new { Area = "Sales" })', {

            type: "POST",
            datatype: "Json",
            data: { CustomerID: $('#CustomerID').val() },
            success: function (data) {
                $('#CustomerContactID').append($('<option></option>').val('').text('Please select'));
                $.each(data, function (index, value) {
                    $('#CustomerContactID').append('<option value="' + value.CustomerContactID + '">' + value.ContactReference + '</option>');
                });
            }
        });
       });
 public JsonResult GetVisitCustomer(string Areas, string term = "")
    {
        var objCustomerlist = db.Customers.Where(c => c.IsDeleted == false)
                        .Where(c => c.DisplayName.ToUpper()
                        .Contains(term.ToUpper()))
                        .Select(c => new { Name = c.DisplayName, ID = c.CustomerID })
                        .Distinct().ToList();
        return Json(objCustomerlist, JsonRequestBehavior.AllowGet);
    }


  public JsonResult GetContactPersobByCustomerId(string customerId)
   {
          Guid Id = Guid.Parse(customerId);
          var customercontacts = (from a in db.CustomerContacts where a.CustomerID == Id select a);
          return Json(customercontacts, JsonRequestBehavior.AllowGet);
   }
如果我键入并选择客户名称则上述代码有效。与客户名称相关的联系人正在联系人下拉列表中加载,但我怀疑我在联系人下拉列表中提供了模糊功能

    $('#CustomerName').blur(function () {
我不知道我的代码是否正确,但它是工作。现在我想要的是请任何人告诉我这个模糊函数的替代或正确代码。 我尽力按照我的水平解释我的问题,任何人都能帮助我解决这个问题

提前谢谢

 public JsonResult GetVisitCustomer(string Areas, string term = "")
    {
        var objCustomerlist = db.Customers.Where(c => c.IsDeleted == false)
                        .Where(c => c.DisplayName.ToUpper()
                        .Contains(term.ToUpper()))
                        .Select(c => new { Name = c.DisplayName, ID = c.CustomerID })
                        .Distinct().ToList();
        return Json(objCustomerlist, JsonRequestBehavior.AllowGet);
    }


  public JsonResult GetContactPersobByCustomerId(string customerId)
   {
          Guid Id = Guid.Parse(customerId);
          var customercontacts = (from a in db.CustomerContacts where a.CustomerID == Id select a);
          return Json(customercontacts, JsonRequestBehavior.AllowGet);
   }
    $('#CustomerName').blur(function () {