2010-12-27 6 views
1

私のアプリケーションでは、ユーザーが定期購入を支払ったかどうかを確認する必要があります。そうでない場合は、更新サービスページにリダイレクトします。グローバルアプリケーションチェックを適用するためのカスタム属性がありますか?

私は、チェックを行うカスタム属性クラスを作成しました。ユーザーがサブスクリプションを支払っていない場合、ビューを変更しました。コードはこちら

public class CheckForActiveServiceAttribute : ActionFilterAttribute { 
    public override void OnActionExecuting(ActionExecutingContext filterContext) { 
     if (!checkForActiveService) { 
      filterContext.Result = new ViewResult { ViewName = "Cart" }; 
     } 
     base.OnActionExecuting(filterContext); 
    } 
} 

これは適切なアプローチですか?また、どのようにして新しいモデルを作成し、それを強い型のビュー "カート"にバインドすることができますか?

答えて

1

1)ええ、どうしてですか?

public class CheckForActiveServiceAttribute : ActionFilterAttribute 
{ 
    public override void OnActionExecuting(ActionExecutingContext filterContext) 
    { 
     if (!false) 
     { 
      filterContext.Result = new ViewResult { ViewName = "Cart" }; 
      ((ViewResultBase)filterContext.Result).ViewData.Model = new MyModel(); 
     } 
     base.OnActionExecuting(filterContext); 
    } 
} 

2)あなたは、次のようなものを使用してビューモデルを設定することができます

関連する問題