0

我想在登录前打开一个对话框,其中包含支持的浏览器列表和继续按钮。以前,我使用包含支持的浏览器列表和显示在主登录视图内的部分视图的 xml 文件来完成它。

但是某些应用程序会覆盖登录视图。所以我决定使用ActionFilterattribute来使用我自己的 CustomFilterAttribute。

我遇到的问题是我想重定向到具有继续按钮并包含所有支持的浏览器以将其显示给用户的部分视图页面。单击继续按钮后,它应该重定向到最初调用的主视图。代码应如下所示

public class BrowserSupportAttribute : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
    SupportedBrowsers supBrowser = new SupportedBrowsers(Request.Browser);
    string strSupportedMessage = null;
    if (supBrowser.SupportStatus != SupportStatus.Supported)
    {
        strSupportedMessage = supBrowser.GetMessage();
        //Code here should contain to redirect to specific partial view which contains
          supported browsers list and after redirecting to partial view I want redirect   to the view which was originally called.
    }
}
}

有什么帮助吗?

4

1 回答 1

0

您可以将 RedirectToRouteResult 对象设置为 filterContext 的 Result 属性,如下所示:

    public class BrowserSupportAttribute : ActionFilterAttribute
    {
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            SupportedBrowsers supBrowser = new SupportedBrowsers(Request.Browser);
            string strSupportedMessage = null;
            if (supBrowser.SupportStatus != SupportStatus.Supported)
            {
                strSupportedMessage = supBrowser.GetMessage();
                filterContext.ActionParameters.Add("message", strSupportedMessage);
                filterContext.ActionParameters.Add("returnUrl", filterContext.HttpContext.Request.Url);
                filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary { { "action", "YOUR_ACTION" }, { "controller", "YOUR_CONTROLLER" } });
            }
        }
    }

以及支持的浏览器视图的操作。

    /// <summary>
    /// Shows the supported browser list.
    /// </summary>
    /// <param name="message">Message for supported browsers.</param>
    /// <param name="returnUrl">The url of the login page.</param>
    public ActionResult YOUR_ACTION(string message, string returnUrl)
    {
        // This is the action to show the view with the supported browsers
        // You can process the ViewBag variables in the view
        ViewBag.Message = message;
        ViewBag.ReturnUrl = returnUrl;

        return View();
    }
于 2013-04-12T12:14:21.000 回答