0

ログインする前に、サポートされているブラウザのリストを含むダイアログ ボックスを [続行] ボタンで開きたいと考えています。以前は、サポートされているブラウザーのリストと、メインのログイン ビュー内に表示される部分ビューを含む xml ファイルを使用して実行していました。

ただし、一部のアプリケーションではログイン ビューがオーバーライドされます。そこで、独自の CustomFilterAttribute を使用するためにActionFilterattributeを使用することにしました。

私が得ている問題は、[続行] ボタンがあり、サポートされているすべてのブラウザーを含む部分ビュー ページにリダイレクトして、ユーザーに表示することです。[続行] ボタンをクリックすると、最初に呼び出されたメイン ビューにリダイレクトされます。コードは次のようになります

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 に答える