开发者

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

开发者 https://www.devze.com 2022-12-29 12:02 出处:网络
Is it possible to开发者_StackOverflow社区 add BindAttribute to parameter in action filter? Each of my view models implements IViewModel { string Prefix { get; } } interface and I would like to set [B

Is it possible to开发者_StackOverflow社区 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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消