ASP.NET MVC ActionFilterAttribute注入价值模型绑定之前 [英] ASP.NET MVC ActionFilterAttribute inject value before model binding
问题描述
我想创建一个自定义操作筛选器属性,增加了项目的HttpContext值将绑定模型中访问。
I would like to create a custom action filter attribute that adds a value in the HttpContext items that would be accessible during model binding.
我试图将它添加在OnActionExecuting,但它似乎在modelbinding过滤器之前exectued。
I have tried to add it in the OnActionExecuting but it that seems the modelbinding is exectued before the filter.
你有什么想法,我怎么能这样做呢?也许有在ModelBinder的一种方法,我可以重写,将过滤后,被解雇,并使用我的筛选器注入的价值。
Do you have any idea how I could do it? Maybe there's a method in the modelbinder that I could override that will be fired after the filter and use the value injected by my filter.
我想要做什么,是注入一个验证上下文(我使用的验证库支持的背景下,这是nvalid.net(www.nvalid.net)
What I want to do, is to inject a validation context (the library I use for validation supports context, it is nvalid.net (www.nvalid.net)
我想是能够把一个属性如
I would like to be able to place an attribute such as
[ValidationContext("Prevalidation")]
在我的ActionResult方法,使发生在我的自定义模型绑定验证能够知道使用哪些方面做验证的时候。
on my actionresult method, so that the validation that occurs in my custom model binder could know which context to use when doing the Validation.
这就是为什么我不能简单地做一个自定义模型粘合剂。
That's why I can't simply make a custom model binder.
推荐答案
为什么不能简单地写在 BindModel 方法?
Why not simply writing a custom model binder and work in the BindModel method?
这篇关于ASP.NET MVC ActionFilterAttribute注入价值模型绑定之前的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!