如何使用jQuery调用MVC ChildActionOnly控制器动作 [英] How to call MVC ChildActionOnly Controller Action using jQuery

查看:72
本文介绍了如何使用jQuery调用MVC ChildActionOnly控制器动作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在部分视图中有一个DropDownListFor.更改后,它将触发jQuery脚本,但Fiddler显示HTTP 500错误:

I have a DropDownListFor that is in a Partial View. On change it fires a jQuery script, but Fiddler shows an HTTP 500 Error:

The action 'LanguageListPartial' is accessible only by a child request.

调用脚本:

<script type="text/javascript">
    $(function () {
        $('#SelectedLanguage').on('change', function () {
            var culture = $(this).val();
            $('#test').load("/Account/LanguageListPartial/" + culture, function () {
                location.reload(true);
            });
        });
    });
</script>

我不希望直接调用Controller Action,所以用 [ChildActionOnly] 装饰它.我意识到它是直接用jQuery .load()调用的.

I wouldn't want that Controller Action called directly so it is decorated with [ChildActionOnly]. I realize that it's being called directly with the jQuery .load().

是否有一种方法可以保留 ChildActionOnly 限制,并且仍然通过 .on('change'...)事件从jQuery调用它?

Is there a way to keep the ChildActionOnly restriction and still call it from jQuery with the .on('change' ...) event?

推荐答案

不,您不能这样做. ChildActionOnly 属性的全部要点是防止由于用户请求而调用它.

No, you cant do that. The whole point of the ChildActionOnly attribute is to prevent it being invoked as a result of a user request.

这篇关于如何使用jQuery调用MVC ChildActionOnly控制器动作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆