0

I want to do something like this

[MyAttribute(Message="Please upgrade to view " + name)]
public ActionResult Details(string name)
{
    ....
}

I know I can call filterContext.ActionDescriptor.GetParameters() from inside the attribute code itself, but is there any way to use them in the controller?

1 Answer 1

2

The correct way to achieve this is to use a custom action filter and inside use either filterContext.ActionDescriptor.GetParameters() or fetch the required parameter from RouteData. You cannot have dynamic values in an attribute declaration because attributes represent metadata that are baked into the assembly at compile time => .NET doesn't allow you this. Only static or constant parameters could be used at attribute declaration.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.