KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I'm trying to create a custom ActionFilter which operates on a set of parameters that would be passed to it from the controller. So far, my customer ActionFilter looks like this: public class CheckLoggedIn : ActionFilterAttribute { public IGenesisRepository gr { get; set; } public Guid memberGuid { get; set; } public override void OnActionExecuting(ActionExecutingContext filterContext) { Member thisMember = gr.GetActiveMember(memberGuid); Member bottomMember = gr.GetMemberOnBottom(); if (thisMember.Role.Tier <= bottomMember.Role.Tier) { filterContext .HttpContext .Response .RedirectToRoute(new { controller = "Member", action = "Login" }); } base.OnActionExecuting(filterContext); } } I know I still need to check for nulls, etc. but I can't figure out why gr and memberGuid aren't successfully being passed. I'm calling this Filter like this: [CheckLoggedIn(gr = genesisRepository, memberGuid = md.memberGUID)] public ActionResult Home(MemberData md) { return View(md); } genesisRepository and md are being set in the controller's constructor. I'm not able to get this to compile. The error I get is: Error 1 'gr' is not a valid named attribute argument because it is not a valid attribute parameter type Error 2 'memberGuid' is not a valid named attribute argument because it is not a valid attribute parameter type I double checked that gr and memberGuid were the same types as genesisRepority and md.memberGUID , What is causing these errors? Solution Thanks to jfar for offering a solution. Here's the Filter I ended up using: public class CheckLoggedIn :
Tags (comma-separated)
Save Edits
Cancel