Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/16.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
Asp.net mvc 使用自定义操作筛选器属性时出现意外行为_Asp.net Mvc_Asp.net Mvc 4 - Fatal编程技术网

Asp.net mvc 使用自定义操作筛选器属性时出现意外行为

Asp.net mvc 使用自定义操作筛选器属性时出现意外行为,asp.net-mvc,asp.net-mvc-4,Asp.net Mvc,Asp.net Mvc 4,我试图重现boiler plate account action filter所具有的相同功能,但执行操作所需的值不同。我遇到了一种奇怪的情况。以下是我的ActionFilterAttribute定义: public class RequireMemberSelectionAttribute : ActionFilterAttribute { /// <summary> /// When the decorated action is executing, redir

我试图重现boiler plate account action filter所具有的相同功能,但执行操作所需的值不同。我遇到了一种奇怪的情况。以下是我的
ActionFilterAttribute
定义:

public class RequireMemberSelectionAttribute : ActionFilterAttribute
{
    /// <summary>
    /// When the decorated action is executing, redirect to the member selection view if a member is not selected.
    /// </summary>
    /// <param name="a_filterContext">Filter context.</param>
    public override void OnActionExecuting(ActionExecutingContext a_filterContext)
    {
        if ((Session.Current.Preferences.MemberID ?? 0) > 0)
            return;

        String returnUrl = null;
        if (a_filterContext.HttpContext.Request.Url != null)
            returnUrl = a_filterContext.HttpContext.Request.Url.PathAndQuery;

        a_filterContext.Redirect("Builder", "ListMembers", new { ReturnUrl=returnUrl });
    }
}
意外的行为是,当在
ListMembers.cshtml
视图上单击链接时,它不会转到
SelectMember
操作,而是尝试转到
SelectArea
,然后重新开始

以下是
ListMembers.cshtml
的确切链接。我从浏览器中的渲染页面复制了它:

我觉得动作过滤器有些地方我不明白

以下是我如何在razor视图中生成链接:

@Html.ActionLink("Test Link", "SelectMember", new { id = 1, returnUrl = ViewBag.ReturnUrl })

如何在
ListMembers.cshtml
中生成链接?这是一个公平的问题。我使用
Html.ActionLink
。我在上面的帖子末尾添加了这一行。我会仔细检查一下,如果你这样做,session.Preferences.MemberID=id反映在您的筛选器
会话.Current.Preferences.MemberID中的代码>SelectMember操作中的重定向永久性是什么?这是否指示浏览器在请求Builder/SelectMember/1时始终转到Builder/SelectArea?请参阅,我认为
RedirectPermanent
意味着当前页面将在历史日志中被覆盖。这是完全不同的。像往常一样,MSDN文档什么也没告诉我。我应该在谷歌上查一下。我该怎么做我想做的事?
@Html.ActionLink("Test Link", "SelectMember", new { id = 1, returnUrl = ViewBag.ReturnUrl })