C# 将Json对象从我的操作过滤器类传递到我的ajax.actionlink

C# 将Json对象从我的操作过滤器类传递到我的ajax.actionlink,c#,javascript,jquery,asp.net,linq,C#,Javascript,Jquery,Asp.net,Linq,我的asp.net MVC web应用程序中有以下操作筛选器类,用于执行自定义授权检查:- public class CheckUserPermissionsAttribute : ActionFilterAttribute { public string Model { get; set; } public string Action { get; set; } public override void OnActionExecuting(ActionExecuti

我的asp.net MVC web应用程序中有以下操作筛选器类,用于执行自定义授权检查:-

public class CheckUserPermissionsAttribute : ActionFilterAttribute
{ 
    public string Model { get; set; }
    public string Action { get; set; }

    public override void OnActionExecuting(ActionExecutingContext filterContext)
    {
        //code goes here….
        if (filterContext.HttpContext.Request.IsAjaxRequest())
        {
            var viewResult = new JsonResult();
            viewResult.Data = (new { IsSuccess = "Unauthorized", description = "You are not authorized to perform this Action." });
            filterContext.Result = viewResult;
        }
    }

    base.OnActionExecuting(filterContext);
}}}
@Ajax.ActionLink("Show Related Servers", "CustomerServer","Customer",
    new {customerID = Model.ORG_ID},
    new AjaxOptions {
 InsertionMode = InsertionMode.Replace,
 UpdateTargetId = "detail"  ,
 LoadingElementId = "progress",

 OnSuccess="detailsuccess"}
我有以下ajax.actinolink,它将调用一个操作方法并执行授权检查:-

public class CheckUserPermissionsAttribute : ActionFilterAttribute
{ 
    public string Model { get; set; }
    public string Action { get; set; }

    public override void OnActionExecuting(ActionExecutingContext filterContext)
    {
        //code goes here….
        if (filterContext.HttpContext.Request.IsAjaxRequest())
        {
            var viewResult = new JsonResult();
            viewResult.Data = (new { IsSuccess = "Unauthorized", description = "You are not authorized to perform this Action." });
            filterContext.Result = viewResult;
        }
    }

    base.OnActionExecuting(filterContext);
}}}
@Ajax.ActionLink("Show Related Servers", "CustomerServer","Customer",
    new {customerID = Model.ORG_ID},
    new AjaxOptions {
 InsertionMode = InsertionMode.Replace,
 UpdateTargetId = "detail"  ,
 LoadingElementId = "progress",

 OnSuccess="detailsuccess"}
Onsuccess脚本是:-

function detailsuccess(data) {
   if (data.IsSuccess == "Unauthorized") {

       jAlert(data.description, 'Unauthorized Access');
   }}
行动方法是:-

 [CheckUserPermissions(Action = "Read", Model = "Server")]
     public ActionResult CustomerServer(int customerID,int page=1) {

但我面临的问题是,如果操作过滤器返回Json对象,那么Onsuccess脚本Inside my ajax链接将不会接收Json对象,并且不会显示JAlert,甚至Onsuccess脚本也不会启动?

John,很抱歉,我现在没有时间发布代码。只留下这个注释:由Microsoft编写脚本并从服务器接收ajax响应的客户端处理程序需要html。当它接收到json时,它不知道该做什么。1.过滤器应设置适当的未授权状态代码(401),而不是返回json。2.您应该创建一个javascript“detailError”函数,并将其添加到razor文件中ActionLink的“OneError”属性中,就像您对回复的“OnSuccess”属性Tanks所做的那样,但是当我在某些功能上使用ajax.beginform而不是ajax.ActionLink时,我能够将JSON对象传递给OnSuccess脚本。。