Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/377.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/csharp/257.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
Javascript ajax验证后,C#MVC JS无法在局部视图上工作/运行_Javascript_C#_Ajax_Model View Controller - Fatal编程技术网

Javascript ajax验证后,C#MVC JS无法在局部视图上工作/运行

Javascript ajax验证后,C#MVC JS无法在局部视图上工作/运行,javascript,c#,ajax,model-view-controller,Javascript,C#,Ajax,Model View Controller,我有一个布局,在我的布局中,我调用我视图中的脚本代码 @if (IsSectionDefined("VSscript")) { @RenderSection("VSscript"); } 我有一个视图,在我的视图中有脚本部分@section VSscript{ 我还有一个连接到partialview的ajax部分 @using (Ajax.BeginForm("CreateServiceQuote", "Service", new AjaxOptions() {

我有一个布局,在我的布局中,我调用我视图中的脚本代码

@if (IsSectionDefined("VSscript"))
    {
        @RenderSection("VSscript");
    }
我有一个视图,在我的视图中有脚本部分
@section VSscript{
我还有一个连接到partialview的ajax部分

@using (Ajax.BeginForm("CreateServiceQuote", "Service", new AjaxOptions() { HttpMethod = "POST", UpdateTargetId = "ajaxCreate", OnSuccess="quoteSuccess" }))
在ajax部分,我有我的部分代码

@Html.Partial("SQcreate")
我使用的所有javascript都在VSscript中,这在我的视图中。 在局部视图中,我只有所需的控件。 当我第一次运行该项目时,一切都很好。在我运行1组验证之后,javascript不再运行。我的ajaxonsuccess=“部分始终运行,但我的文档中所需的代码。ready不会运行。 这是我的控制器,它只是调用部分视图,如果它无效

public ActionResult SQcreate()
        {
            var model = new ServiceModel();
            return PartialView(model);
        }
        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult CreateServiceQuote(ServiceModel model)
        {
                if (ModelState.IsValid)
            {

                context.Serv_Quotes.Add(serviceQuote);
                context.SaveChanges();                
                ModelState.Clear();

                return Json("QuoteSuccess", JsonRequestBehavior.AllowGet);
            }            
            return PartialView("SQcreate", serviceModel);
        }
这是布局图

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>@ViewBag.Titler</title>
    @Styles.Render("~/Content/css")
    @Styles.Render("~/Content/themes/base/css")
    @Scripts.Render("~/bundles/modernizr")
    @if (IsSectionDefined("VSscript"))
    {
        @*@RenderSection("VSscript");*@
        @RenderSection("VSscript", required: false)

    }    
</head>
<body style="padding-top: 0px;">    
    <div class="container-fluid">
        @RenderBody()
    </div>
    <!-- Script Bundle 1 -->
    @Scripts.Render("~/bundles/jquery")
    @Scripts.Render("~/bundles/jQueryValScripts")
    <!-- ORRR Script Bundle 2 MINIFIED -->
    <!--Scripts.Render("~/bundles/jQueryValScripts")-->
    <!--*Scripts.Render("~/bundles/jqueryui")*-->
    <!--*Scripts.Render("~/bundles/bootstrap")-->
    <!--*Scripts.Render("~/bundles/unobtrusive")*-->
    @*@RenderSection("VSscript", required: false)*@
</body>
</html>

@书名
@style.Render(“~/Content/css”)
@style.Render(“~/Content/themes/base/css”)
@Scripts.Render(“~/bundles/modernizer”)
@如果(IsSectionDefined(“VSscript”))
{
@*@渲染部分(“VSscript”)*@
@RenderSection(“VSscript”,必需:false)
}    
@RenderBody()
@Scripts.Render(“~/bundles/jquery”)
@Scripts.Render(“~/bundles/jQueryValScripts”)
@*@RenderSection(“VSscript”,必需:false)*@
那景色呢

@model PartNumbers.Models.ServiceModel
@{
    HtmlHelper.UnobtrusiveJavaScriptEnabled = true;
    Layout = "~/Views/Shared/_LayoutPageI.cshtml";
    ViewBag.Title = "Virtual Service";

    //TempData["EmployeeID"] == null ? "" : TempData["EmployeeID"];
}
@section VSscript {
    <script type="text/javascript">
    $(function () {
$("#btnSQopenCon").on("click", function () {
            $("#AddSQcontact").modal("show");
        })

        // jQuery UI Date Picker Class Object Name
        $(".datepickerui").datepicker();

        var modalQ = $('#AddQuote');
        var custDDL = modalQ.find('.modal-body').find('#ServiceVM_CustomerName');
        var sn2DDL = modalQ.find('.modal-body').find('#ServiceVM_SN2');
        $(custDDL).change(function () {
            //alert('testtesttest');
            var cityName = $(custDDL).val();
            var sn2Number = $(sn2DDL).val();
            $.ajax({
                url: '@Url.Action("SearchContactsList", "Service")',
                data: { Customer: cityName, SN2: sn2Number },
                datatype: "json",
                success: function (data) {
                    //var dropdownlist = $('#ContactSearch');
                    var dropdownlist = modalQ.find('.modal-body').find('#ServiceVM_ContactName');
                        //$('#ServiceVM_ContactName');
                    dropdownlist.empty();
                    $.each(data, function () {
                        dropdownlist.append(
                            $('<option></option>').val(this.Value).html(this.Text)
                        );
                    });
                }
            });
        });
})
function quoteSuccess(data) {
        if (data == 'QuoteSuccess') {
            $("#AddQuote").modal("hide");
            window.location.reload();
            //var quoteRefresh =
            //$.ajax({

            //})
        }
function contactSuccess(data) {
        if (data == "ContactSuccess") {
            $("#AddSQcontact").modal("hide");
            var modalQ = $('#AddQuote');
            var custDDL = modalQ.find('.modal-body').find('#ServiceVM_CustomerName').val();
            var sn2DDL = modalQ.find('.modal-body').find('#ServiceVM_SN2').val();

            $.ajax({
                url: '@Url.Action("SearchContactsList", "Service")',
                data: { Customer: custDDL, SN2: sn2DDL },
                datatype: 'json',
                success: function (data) {
                    var dropdownlist = modalQ.find('.modal-body').find('#ServiceVM_ContactName');
                    dropdownlist.empty();
                    $.each(data, function () {
                        dropdownlist.append(
                            $('<option></option>').val(this.Value).html(this.Text)
                        );
                    });
                }
            });
    </script>
}
<!-- CREATE Service Quote -->
@using (Ajax.BeginForm("CreateServiceQuote", "Service", new AjaxOptions() { HttpMethod = "POST", UpdateTargetId = "ajaxCreate", OnSuccess="quoteSuccess" }))
{
    <div class="modal" id="AddQuote" tabindex="-1" role="dialog" aria-labelledby="lblAjaxCreate" aria-hidden="true">
        <div class="modal-dialog" role="document" style="width:750px;">
            <div class="modal-content">
                <div class="modal-header">
                    <h3 class="modal-title text-center"><b>New Service Quote</b></h3>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <div class="modal-body" id="ajaxCreate">
                    @Html.Partial("SQcreate")
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
                    <input type="submit" class="btn btn-success" value="Create Quote" />
                </div>
            </div>
        </div>
    </div>
}

<!-- CREATE CONTACT -->
@using (Ajax.BeginForm("CreateSQcontact", "Service", new AjaxOptions() { HttpMethod = "POST", UpdateTargetId = "ajaxContact", OnSuccess = "contactSuccess" }))
{
    <div class="modal" id="AddSQcontact" tabindex="-1" role="dialog" aria-labelledby="lblAjaxContact" aria-hidden="true">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h3 class="text-center"><b>Create Contact</b></h3>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <div class="modal-body" id="ajaxContact">
                    @Html.Partial("SQcontact")
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
                    <input type="submit" class="btn btn-success" value="Create Contact" />
                </div>
            </div>
        </div>
    </div>
}
@model partnumber.Models.ServiceModel
@{
HtmlHelper.UnobtrusiveJavaScriptEnabled=true;
Layout=“~/Views/Shared/_LayoutPageI.cshtml”;
ViewBag.Title=“虚拟服务”;
//TempData[“EmployeeID”]==null?”:TempData[“EmployeeID”];
}
@节VSscript{
$(函数(){
$(“#btnSQopenCon”)。在(“单击”,函数(){
$(“#AddSQcontact”).modal(“show”);
})
//jQuery UI日期选择器类对象名称
$(“.datepickerui”).datepicker();
var modalQ=$(“#AddQuote”);
var custdl=modalQ.find('.modal body').find('#ServiceVM_CustomerName');
var sn2DDL=modalQ.find('.modal body').find('#ServiceVM_SN2');
$(custdll).change(函数(){
//警报(“测试”);
var cityName=$(custdll.val();
var sn2Number=$(sn2DDL.val();
$.ajax({
url:'@url.Action(“SearchContactsList”,“Service”),
数据:{Customer:cityName,SN2:sn2Number},
数据类型:“json”,
成功:功能(数据){
//var dropdownlist=$(“#ContactSearch”);
var dropdownlist=modalQ.find('.modal body').find('#ServiceVM_ContactName');
//$(“#ServiceVM_ContactName”);
dropdownlist.empty();
$。每个(数据、函数(){
dropdownlist.append(
$('').val(this.Value).html(this.Text)
);
});
}
});
});
})
函数引用成功(数据){
如果(数据=='QuoteSuccess'){
$(“#AddQuote”).modal(“隐藏”);
window.location.reload();
//var quoteRefresh=
//$.ajax({
//})
}
函数contactSuccess(数据){
如果(数据==“ContactSuccess”){
$(“#AddSQcontact”).modal(“隐藏”);
var modalQ=$(“#AddQuote”);
var custdl=modalQ.find('.modal body').find('#ServiceVM_CustomerName').val();
var sn2DDL=modalQ.find('.modal body').find('#ServiceVM_SN2').val();
$.ajax({
url:'@url.Action(“SearchContactsList”,“Service”),
数据:{Customer:custdll,SN2:sn2DDL},
数据类型:“json”,
成功:功能(数据){
var dropdownlist=modalQ.find('.modal body').find('#ServiceVM_ContactName');
dropdownlist.empty();
$。每个(数据、函数(){
dropdownlist.append(
$('').val(this.Value).html(this.Text)
);
});
}
});
}
@使用(Ajax.BeginForm(“CreateServiceQuote”,“Service”,new AjaxOptions(){HttpMethod=“POST”,UpdateTargetId=“ajaxCreate”,OnSuccess=“quoteSuccess”}))
{
新服务报价
&时代;
@Html.Partial(“SQcreate”)
接近
}
@使用(Ajax.BeginForm(“CreateSQcontact”,“Service”,new AjaxOptions(){HttpMethod=“POST”,UpdateTargetId=“ajaxContact”,OnSuccess=“contactSuccess”}))
{
建立联系
&时代;
@Html.Partial(“SQcontact”)
接近
}

我的解决方案是查看开发工具中的“网络选项卡”。我在那里发现了一些错误,关于切换和重新加载视图时未加载部分模型