自定义属性是否适合应用全局应用程序检查?
在我的应用程序中,我需要检查用户是否已支付订阅费用,如果没有,则将其重定向到续订服务页面。
然后,我创建了一个自定义属性类来执行检查,如果用户尚未支付订阅费用,则更改视图。这是代码
public class CheckForActiveServiceAttribute : ActionFilterAttribute {
public override void OnActionExecuting( ActionExecutingContext filterContext ) {
if ( !checkForActiveService ) {
filterContext.Result = new ViewResult { ViewName = "Cart" };
}
base.OnActionExecuting( filterContext );
}
}
这是遵循的正确方法吗?另外,如何创建一个新模型并将其绑定到强类型视图“Cart”?
In my application I have the requirement to check if the user has paid the subscription and if not, redirect him to a renew service page.
I have then created a custom attribute class that does the check and if the user has not paid the subscription change the View. Here is the code
public class CheckForActiveServiceAttribute : ActionFilterAttribute {
public override void OnActionExecuting( ActionExecutingContext filterContext ) {
if ( !checkForActiveService ) {
filterContext.Result = new ViewResult { ViewName = "Cart" };
}
base.OnActionExecuting( filterContext );
}
}
Is this the right approach to follow? Also, how can I create a new model and bind it to the strong-typed view "Cart"?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
1)是啊,为什么不呢?
2)您可以使用类似以下内容设置视图模型:
1) Yeah, why not?
2) You can set the view model using something like the following: