调用父视图';s部分视图中的javascript函数';s javascript函数

调用父视图';s部分视图中的javascript函数';s javascript函数,javascript,asp.net-mvc,Javascript,Asp.net Mvc,我在父视图中有一个javascript函数,比如Check(),这个父视图有一个称为child的部分视图。这个子视图中有一个java脚本函数,它将在锚定标记单击后触发,然后调用父视图的Check()函数 所以我需要的是从这个局部视图的函数调用父视图的Check()函数简单地将父视图的脚本函数放在部分视图中不会调用Check()。我该怎么做,请纠正我的错误 这就是我到目前为止所做的 我的局部视图脚本函数如下所示 function supp_checkAndReset(elem) { var

我在父视图中有一个javascript函数,比如
Check()
,这个父视图有一个称为child的部分视图。这个子视图中有一个java脚本函数,它将在锚定标记单击后触发,然后调用父视图的
Check()
函数

所以我需要的是从这个局部视图的函数调用父视图的
Check()
函数简单地将父视图的脚本函数放在部分视图中不会调用
Check()
。我该怎么做,请纠正我的错误

这就是我到目前为止所做的

我的局部视图脚本函数如下所示

function supp_checkAndReset(elem) {
    var currentSelected = $(elem).attr('id');
    $('.supp_panelfilterresultholder span[title="' + currentSelected + '"]').remove();
    $('.supp_panelfiltersuggestion input[value="' + currentSelected + '"]').prop('checked', false);

    Check();
 }
 function Check() {
        var supp_fullCheckList = $("#supp_filterWithThis").val();
        var practice_fullCheckList = $("#practice_filterWithThis").val();
        var county_fullCheckList = $("#county_filterWithThis").val();
        var state_fullCheckList = $("#state_filterWithThis").val();

        var ratebase_sliderValue = $("#ratebase_sliderValue").val();
        var clientRating_sliderValue = $("#clientRating_sliderValue").val();
        var panelRating_sliderValue = $("#panelRating_sliderValue").val();

        $.ajax({
            url: '@Url.Action("GetSearchResultBasedOnFilters", "SearchResult")',
            type: 'GET',
            data: {
                supp_fullCheckList: supp_fullCheckList, practice_fullCheckList: practice_fullCheckList, county_fullCheckList: county_fullCheckList,
                state_fullCheckList: state_fullCheckList, ratebase_sliderValue: ratebase_sliderValue, clientRating_sliderValue: clientRating_sliderValue, panelRating_sliderValue: panelRating_sliderValue
            },
            success: function (response) {
                var totRecordCount = $('#RecordTotalCount').val();

                $('#TotRecordCount').html(totRecordCount);

                $('#searchArea').html('');
                $('#searchArea').html(response);
            },
        error: function (xhr, status, error) {
            alert(status + " : " + error);
        }});
    }
我的父视图脚本函数位于脚本标记下,如下所示

function supp_checkAndReset(elem) {
    var currentSelected = $(elem).attr('id');
    $('.supp_panelfilterresultholder span[title="' + currentSelected + '"]').remove();
    $('.supp_panelfiltersuggestion input[value="' + currentSelected + '"]').prop('checked', false);

    Check();
 }
 function Check() {
        var supp_fullCheckList = $("#supp_filterWithThis").val();
        var practice_fullCheckList = $("#practice_filterWithThis").val();
        var county_fullCheckList = $("#county_filterWithThis").val();
        var state_fullCheckList = $("#state_filterWithThis").val();

        var ratebase_sliderValue = $("#ratebase_sliderValue").val();
        var clientRating_sliderValue = $("#clientRating_sliderValue").val();
        var panelRating_sliderValue = $("#panelRating_sliderValue").val();

        $.ajax({
            url: '@Url.Action("GetSearchResultBasedOnFilters", "SearchResult")',
            type: 'GET',
            data: {
                supp_fullCheckList: supp_fullCheckList, practice_fullCheckList: practice_fullCheckList, county_fullCheckList: county_fullCheckList,
                state_fullCheckList: state_fullCheckList, ratebase_sliderValue: ratebase_sliderValue, clientRating_sliderValue: clientRating_sliderValue, panelRating_sliderValue: panelRating_sliderValue
            },
            success: function (response) {
                var totRecordCount = $('#RecordTotalCount').val();

                $('#TotRecordCount').html(totRecordCount);

                $('#searchArea').html('');
                $('#searchArea').html(response);
            },
        error: function (xhr, status, error) {
            alert(status + " : " + error);
        }});
    }

我也有同样的问题。将java脚本函数
supp\u checkAndReset(elem)
Check()
保留在主视图中,即父视图中。因此,可以从视图和局部视图访问它

在父视图中应该是这样的

<script type="text/javascript">
function supp_checkAndReset(elem) {
var currentSelected = $(elem).attr('id');
$('.supp_panelfilterresultholder span[title="' + currentSelected + '"]').remove();
$('.supp_panelfiltersuggestion input[value="' + currentSelected + '"]').prop('checked', false);

Check();
}
 function Check() {
    var supp_fullCheckList = $("#supp_filterWithThis").val();
    var practice_fullCheckList = $("#practice_filterWithThis").val();
    var county_fullCheckList = $("#county_filterWithThis").val();
    var state_fullCheckList = $("#state_filterWithThis").val();

    var ratebase_sliderValue = $("#ratebase_sliderValue").val();
    var clientRating_sliderValue = $("#clientRating_sliderValue").val();
    var panelRating_sliderValue = $("#panelRating_sliderValue").val();

    $.ajax({
        url: '@Url.Action("GetSearchResultBasedOnFilters", "SearchResult")',
        type: 'GET',
        data: {
            supp_fullCheckList: supp_fullCheckList, practice_fullCheckList: practice_fullCheckList, county_fullCheckList: county_fullCheckList,
            state_fullCheckList: state_fullCheckList, ratebase_sliderValue: ratebase_sliderValue, clientRating_sliderValue: clientRating_sliderValue, panelRating_sliderValue: panelRating_sliderValue
        },
        success: function (response) {
            var totRecordCount = $('#RecordTotalCount').val();

            $('#TotRecordCount').html(totRecordCount);

            $('#searchArea').html('');
            $('#searchArea').html(response);
        },
    error: function (xhr, status, error) {
        alert(status + " : " + error);
    }});
}

功能支持检查和设置(elem){
var currentSelected=$(elem).attr('id');
$('.supp_panelfilterresultholder span[title=“”+currentSelected+“]”)。删除();
$('.supp_panelfiltersuggestion输入[value=“+currentSelected+”).prop('checked',false);
检查();
}
函数检查(){
var supp_fullCheckList=$(“#supp_filter with this”).val();
var practice_fullCheckList=$(“#practice_filter with this”).val();
var country_fullCheckList=$(“#country_filterWithThis”).val();
var state_fullCheckList=$(“#state_filterWithThis”).val();
var ratebase_sliderValue=$(“#ratebase_sliderValue”).val();
var clientRating_sliderValue=$(“#clientRating_sliderValue”).val();
var panelRating_sliderValue=$(“#panelRating_sliderValue”).val();
$.ajax({
url:'@url.Action(“GetSearchResultBasedFilters”,“SearchResult”),
键入:“GET”,
数据:{
支持完整清单:支持完整清单,实践完整清单:实践完整清单,县完整清单:县完整清单,
state\u fullCheckList:state\u fullCheckList,ratebase\u sliderValue:ratebase\u sliderValue,clientRating\u sliderValue:clientRating\u sliderValue,panelRating\u sliderValue:panelRating\u sliderValue
},
成功:功能(响应){
var totRecordCount=$('#RecordTotalCount').val();
$('#TotRecordCount').html(TotRecordCount);
$('#searchArea').html('');
$('#searchArea').html(回复);
},
错误:函数(xhr、状态、错误){
警报(状态+”:“+错误);
}});
}

我也有同样的问题。将java脚本函数
supp\u checkAndReset(elem)
Check()
保留在主视图中,即父视图中。因此,可以从视图和局部视图访问它

在父视图中应该是这样的

<script type="text/javascript">
function supp_checkAndReset(elem) {
var currentSelected = $(elem).attr('id');
$('.supp_panelfilterresultholder span[title="' + currentSelected + '"]').remove();
$('.supp_panelfiltersuggestion input[value="' + currentSelected + '"]').prop('checked', false);

Check();
}
 function Check() {
    var supp_fullCheckList = $("#supp_filterWithThis").val();
    var practice_fullCheckList = $("#practice_filterWithThis").val();
    var county_fullCheckList = $("#county_filterWithThis").val();
    var state_fullCheckList = $("#state_filterWithThis").val();

    var ratebase_sliderValue = $("#ratebase_sliderValue").val();
    var clientRating_sliderValue = $("#clientRating_sliderValue").val();
    var panelRating_sliderValue = $("#panelRating_sliderValue").val();

    $.ajax({
        url: '@Url.Action("GetSearchResultBasedOnFilters", "SearchResult")',
        type: 'GET',
        data: {
            supp_fullCheckList: supp_fullCheckList, practice_fullCheckList: practice_fullCheckList, county_fullCheckList: county_fullCheckList,
            state_fullCheckList: state_fullCheckList, ratebase_sliderValue: ratebase_sliderValue, clientRating_sliderValue: clientRating_sliderValue, panelRating_sliderValue: panelRating_sliderValue
        },
        success: function (response) {
            var totRecordCount = $('#RecordTotalCount').val();

            $('#TotRecordCount').html(totRecordCount);

            $('#searchArea').html('');
            $('#searchArea').html(response);
        },
    error: function (xhr, status, error) {
        alert(status + " : " + error);
    }});
}

功能支持检查和设置(elem){
var currentSelected=$(elem).attr('id');
$('.supp_panelfilterresultholder span[title=“”+currentSelected+“]”)。删除();
$('.supp_panelfiltersuggestion输入[value=“+currentSelected+”).prop('checked',false);
检查();
}
函数检查(){
var supp_fullCheckList=$(“#supp_filter with this”).val();
var practice_fullCheckList=$(“#practice_filter with this”).val();
var country_fullCheckList=$(“#country_filterWithThis”).val();
var state_fullCheckList=$(“#state_filterWithThis”).val();
var ratebase_sliderValue=$(“#ratebase_sliderValue”).val();
var clientRating_sliderValue=$(“#clientRating_sliderValue”).val();
var panelRating_sliderValue=$(“#panelRating_sliderValue”).val();
$.ajax({
url:'@url.Action(“GetSearchResultBasedFilters”,“SearchResult”),
键入:“GET”,
数据:{
支持完整清单:支持完整清单,实践完整清单:实践完整清单,县完整清单:县完整清单,
state\u fullCheckList:state\u fullCheckList,ratebase\u sliderValue:ratebase\u sliderValue,clientRating\u sliderValue:clientRating\u sliderValue,panelRating\u sliderValue:panelRating\u sliderValue
},
成功:功能(响应){
var totRecordCount=$('#RecordTotalCount').val();
$('#TotRecordCount').html(TotRecordCount);
$('#searchArea').html('');
$('#searchArea').html(回复);
},
错误:函数(xhr、状态、错误){
警报(状态+”:“+错误);
}});
}

使用开发工具检查控制台是否存在错误我已检查,但未定义检查。更好的方法是在单独的js文件中添加js,并将其包含在主控文件中layout@EhsanSajjad我做的和你说的一样,但是现在我得到了控制台错误,因为“路径中的非法字符”部分视图不应该包含脚本。将其包含在主视图中。使用开发工具检查控制台是否存在错误我已检查,但未定义检查。更好的方法是在单独的js文件中添加js,并将其包含在主视图中layout@EhsanSajjad我做的和你说的一样,但是现在我得到了控制台错误,因为“路径中的非法字符”部分视图不应该包含脚本。将其包含在主视图中。实际上没有发生任何事情清理解决方案、cookies并重试。我发现了问题,不调用或不获取父函数的原因是,我已将Cehck()函数放在父视图的docuement ready标记中。当我把它放在外面的时候,现在我接到了我孩子的电话。非常感谢您的帮助。实际上什么也没有发生清理解决方案、cookies并重试。我发现了问题,不调用或不获取父函数的原因是,我已将Cehck()函数放在父视图的docuement ready标记中。当我把它放在外面的时候,现在我接到了我孩子的电话。非常感谢你的帮助。