Feryt
Feryt

Reputation: 2302

ASP.NET MVC 2: add Bind(Prefix) attribute in ActionFilter

Is it possible to add BindAttribute to parameter in action filter?

Each of my view models implements IViewModel { string Prefix { get; } } interface and I would like to set [Bind(Prefix = Model.Prefix)] for Action parameter automatically.

Upvotes: 0

Views: 754

Answers (1)

Darin Dimitrov
Darin Dimitrov

Reputation: 1038780

You cannot apply attributes at runtime, they are metadata and are baked into the assembly at compile-time, that's the reason you cannot write [Bind(Prefix = Model.Prefix)]. Model.Prefix needs to be constant and known at compile-time for this to work. Could you describe your scenario in more details, maybe there's another way to achieve your goal.

Upvotes: 1

Related Questions