Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/288.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# 匿名函数错误和什么是匿名函数?_C#_Jquery_Ajax_Twitter Bootstrap_Asp.net Mvc 4 - Fatal编程技术网

C# 匿名函数错误和什么是匿名函数?

C# 匿名函数错误和什么是匿名函数?,c#,jquery,ajax,twitter-bootstrap,asp.net-mvc-4,C#,Jquery,Ajax,Twitter Bootstrap,Asp.net Mvc 4,嗨,我在我的项目中有一个视图叫做访问者视图。在该视图中,它包含两个下拉列表CustomerName和ContactPerson如果我选择CustomerName,则与CustomerName相关的ContactPerson名称将自动加载到ContactPerson下拉列表中。这类似于级联下拉列表。这个过程在正常模式下工作正常,也就是说,当我运行我的应用程序时,这个级联下拉列表工作正常。但是,当我在LocalHost中发布项目并运行应用程序时,这两个下拉列表都没有从db加载值。这些级联不起作用。所

嗨,我在我的项目中有一个视图叫做访问者视图。在该视图中,它包含两个下拉列表CustomerName和ContactPerson如果我选择CustomerName,则与CustomerName相关的ContactPerson名称将自动加载到ContactPerson下拉列表中。这类似于级联下拉列表。这个过程在正常模式下工作正常,也就是说,当我运行我的应用程序时,这个级联下拉列表工作正常。但是,当我在LocalHost中发布项目并运行应用程序时,这两个下拉列表都没有从db加载值。这些级联不起作用。所以我在浏览器中检查了这个问题,当时我得到了这些问题。问题如下。请任何人告诉我这是什么问题?给我这个问题的解决办法

我的视图模型

我的看法

我的Jquery


您的匿名函数应如下所示:

(function($){
    $.ajax({
        //etc
    })
})(jQuery)

您使用它的方式$不在匿名函数的作用域内。它必须作为函数参数传入。

找不到错误404。。与匿名函数无关。我认为你试图点击的网址不对。是的,我同意它在你的开发中有效,但在你发布之后就不行了。点击链接后,在上面的错误,你将能够看到实际的错误,你需要张贴你的代码,而不是它的图像!好的,我将发布我的代码。问题是当你点击GetCustomers Url时。直接在URL中键入,让我们知道您看到了什么。http://192.168.0.36:8066/VisitorsForm/GetCustomersMost 你的问题的可能答案-。你能解释一下这个随机代码风格的建议是如何与这个问题相关的吗?这个问题与图中圈出的错误有关。图像中发布的代码与$function{行相关。我试图显示正确的语法,该语法应为function${…这修复了错误。@JimG$function{是正确的。这是文档就绪样式的简写。您发布的代码是一个闭包语法,与此无关question@Reddy好的,谢谢。我想我的想法错了。谢谢你的反馈。
     public ActionResult Create()
    {
      return View();
    }
     public JsonResult GetCustomers()
    {
        return Json(db.Customers.ToList(), 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);
    }
    <div class="col-sm-4">
      <div class="form-group">
        @Html.Label("Customer Name", new { @class = "control-label" })
        @Html.DropDownListFor(model => model.CustomerID, new SelectList(string.Empty, "Value", "Text"), "Please select a Customer", new { @class = "form-control required", type = "text" })
                        </div>
                    </div>

          <div class="col-sm-4">
          <div class="form-group">
         @Html.Label("Contact Person", new { @class = "control-label" })
         @Html.DropDownListFor(model => model.CustomerContactID, new SelectList(string.Empty, "Value", "Text"), "Please select a ContactPerson", new { @class = "form-control", type = "text", id = "CustomerContactID" })
         </div>
         </div>
<script>
 $(function () {
    $.ajax({
        type: "GET",
        url: "/VisitorsForm/GetCustomers",
        datatype: "Json",
        success: function (data) {
            $.each(data, function (index, value) {
                $('#CustomerID').append('<option value="' + value.CustomerID + '">' + value.DisplayName + '</option>');
            });
        }
    });

    $('#CustomerID').change(function () {

        $('#CustomerContactID').empty();

        $.ajax({
            type: "POST",
            url: "/VisitorsForm/GetContactPersobByCustomerId",
            datatype: "Json",
            data: { CustomerID: $('#CustomerID').val() },
            success: function (data) {
                $.each(data, function (index, value) {
                    $('#CustomerContactID').append('<option value="' + value.CustomerContactID + '">' + value.ContactReference + '</option>');
                });
            }
        });
    });
});
(function($){
    $.ajax({
        //etc
    })
})(jQuery)