Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/17.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 未在Chrome和IE中呈现Javascript块_Jquery_Asp.net Mvc_Browser_Partial Views - Fatal编程技术网

Jquery 未在Chrome和IE中呈现Javascript块

Jquery 未在Chrome和IE中呈现Javascript块,jquery,asp.net-mvc,browser,partial-views,Jquery,Asp.net Mvc,Browser,Partial Views,场景 我正在开发一种报表生成器。用户从选择中选择报告并单击按钮。将动态创建并呈现具有所需参数的表单。某些参数呈现为selects,绑定到db表 表格的名称: var data = { 'ReportId': $('#Reports option:selected').val() }; $.ajax({ type: 'GET', url: '/statistics/ReportBuilder/GetReportParameters', dataType: 'text',

场景

我正在开发一种报表生成器。用户从
选择中选择报告并单击按钮。将动态创建并呈现具有所需参数的表单。某些参数呈现为
select
s,绑定到db表

  • 表格的名称:

    var data = { 'ReportId': $('#Reports option:selected').val() };
    $.ajax({
        type: 'GET',
        url: '/statistics/ReportBuilder/GetReportParameters',
        dataType: 'text',
        data: data,
        success: function(data){
            $('#divReportParameters').html(data);
        },
        complete: function(){
            mkNamespace.utils.dom.hideLoader($('#content'));
        }
    });
    
  • GetReportParameters.cshtml
    。表单是由简单容器组成的视图:

          @model ReportBuilderModel
          <div>
              <h3>@Model.Report.Label</h3>
          </div>
          <div>
              <form id='frmReportParameters' action='@Url.Action("GetReport")' method="post">
                  @Html.Partial("~/Views/Shared/Controls/_ParametricForm.cshtml", Model.Parameters)
                  <input type = "hidden" id="reportId" name="reportId" value="@Model.Report.Id" />
                  <input id="btnGetReport" type="button" value="Estrai Report" />
              </form>
          </div>
    
  • 问题

    现在,不要介意所有的细节。所有这些东西都能在Firefox上完美运行

    在Chrome IE中,
    \u ParameterForm
    部分中的
    块在响应中正确返回(通过调试器检查),但不会执行onchange事件处理程序

    因此,问题不在部分视图逻辑中,因为响应是在所有浏览器中正确创建的。但问题似乎与浏览器引擎有关


    如何解决这个问题?

    您将数据类型设置为文本,因此它将把它作为文本处理,而不进行任何处理。设置为“html”。

    如果它是一个表单字段,那么是否合适?如果需要更改,请尝试比较当前值和以前的值以进行更改

    onchange
    仅在控件模糊时触发。()

        @model FormParameterCollection
    
        <table class="tableForm parametricForm">
        @foreach (FormParameter par in Model) { 
            <tr>
                <td class="fieldLabel">@par.Label</td>
                <td class="fieldInput">
                    @switch(par.Type){
                        case FormParameterType.Input:
                            <input name="@par.Name" type="text" class="fieldText" />
                            break;
                        case FormParameterType.Select:
                            <select name="@par.Name" class="fieldSelect">
                            @if (!string.IsNullOrWhiteSpace(par.DefaultLabel) || !string.IsNullOrWhiteSpace(par.DefaultValue))
                            { 
                                <option value="@par.DefaultValue" data-tag="">@par.DefaultLabel</option>
                            }
                            @foreach (DataSourceItem item in DataSourceManager.Current[par.DataSource])
                            {
                                <option value="@item.Value" data-tag="@item.Tag">@item.Label</option>
                            }
                            </select>
                            break;
                        case FormParameterType.MultiSelect:
                            <select name="@par.Name" class="fieldSelect" multiple="multiple" size="6">
                            @if (!string.IsNullOrWhiteSpace(par.DefaultLabel) || !string.IsNullOrWhiteSpace(par.DefaultValue))
                            { 
                                <option value="@par.DefaultValue" data-tag="">@par.DefaultLabel</option>
                            }
                            @foreach (DataSourceItem item in DataSourceManager.Current[par.DataSource])
                            {
                                <option value="@item.Value" data-tag="@item.Tag">@item.Label</option>
                            }
                            </select>
                            break;
                        case FormParameterType.Date:
                            @Html.JQueryUI().Datepicker(par.Name, DateTime.Now)
                            break;
                        default:
                            <input name="@par.Name" type="text" class="fieldText" />
                            break;
                    }
                </td>
            </tr>
        }
        </table>
        <script type="text/javascript">
            //dynamically bind the onchange events of the parametes
            $(document).ready(function(){
                @foreach (FormParameter par in Model) {
                <text>
                    @if(!String.IsNullOrEmpty(par.ParentParameter)){        //the onchange event is bound for the 'parent related' parameters (e.g. shop & categories)
                        <text>
                        $('.tableForm.parametricForm').on('change', '[name="@par.ParentParameter"]', function (e) {
                            var parentId = e.target.value;
    
                            $('[name="@par.Name"] > option').hide();
                            $('[name="@par.Name"] > option').filter(function () {
                                var tag = $(this).attr('data-tag');
                                return (tag == '' ? true : (JSON.parse($(this).attr('data-tag'))['@par.ParentParameter'] == parentId) || (parentId == ''));
                            }).show();
                        });
                        </text>
                    }
                </text>
                }
            });
    
            //bind jQueryUI functions after the ajax call
            $('.tableForm').jQueryUIHelpers();
        </script>