Asp.net mvc 如何在绑定后但在验证之前获取模型?

Asp.net mvc 如何在绑定后但在验证之前获取模型?,asp.net-mvc,asp.net-mvc-validation,asp.net-mvc-filters,Asp.net Mvc,Asp.net Mvc Validation,Asp.net Mvc Filters,是否有可能在binder中创建模型之后但在验证之前对其进行全局拦截。我尝试了筛选器,但在验证后会调用筛选器。尝试自定义模型绑定器。这将在模型验证之前拦截请求管道。实现IModelBinder尝试自定义模型绑定器。这将在模型验证之前拦截请求管道。实现IModelBinder尝试自定义模型绑定器。这将在模型验证之前拦截请求管道。实现IModelBinder尝试自定义模型绑定器。这将在模型验证之前拦截请求管道。实现IModelBinder类似的功能应该可以: public class CustomMo

是否有可能在binder中创建模型之后但在验证之前对其进行全局拦截。我尝试了筛选器,但在验证后会调用筛选器。

尝试自定义模型绑定器。这将在模型验证之前拦截请求管道。实现
IModelBinder

尝试自定义模型绑定器。这将在模型验证之前拦截请求管道。实现
IModelBinder

尝试自定义模型绑定器。这将在模型验证之前拦截请求管道。实现
IModelBinder

尝试自定义模型绑定器。这将在模型验证之前拦截请求管道。实现
IModelBinder

类似的功能应该可以:

public class CustomModelBinder: DefaultModelBinder
{
    protected override void OnModelUpdated(ControllerContext controllerContext, ModelBindingContext bindingContext)
    {
        base.OnModelUpdated(controllerContext, bindingContext);
        //You now have access to "bindingContext.Model" which is your model.
    }
}
然后在
Application\u Start
中的
Globals.asax
(不要忘记这一部分):


像这样的方法应该会奏效:

public class CustomModelBinder: DefaultModelBinder
{
    protected override void OnModelUpdated(ControllerContext controllerContext, ModelBindingContext bindingContext)
    {
        base.OnModelUpdated(controllerContext, bindingContext);
        //You now have access to "bindingContext.Model" which is your model.
    }
}
然后在
Application\u Start
中的
Globals.asax
(不要忘记这一部分):


像这样的方法应该会奏效:

public class CustomModelBinder: DefaultModelBinder
{
    protected override void OnModelUpdated(ControllerContext controllerContext, ModelBindingContext bindingContext)
    {
        base.OnModelUpdated(controllerContext, bindingContext);
        //You now have access to "bindingContext.Model" which is your model.
    }
}
然后在
Application\u Start
中的
Globals.asax
(不要忘记这一部分):


像这样的方法应该会奏效:

public class CustomModelBinder: DefaultModelBinder
{
    protected override void OnModelUpdated(ControllerContext controllerContext, ModelBindingContext bindingContext)
    {
        base.OnModelUpdated(controllerContext, bindingContext);
        //You now have access to "bindingContext.Model" which is your model.
    }
}
然后在
Application\u Start
中的
Globals.asax
(不要忘记这一部分):


你想实现什么?你想实现什么?你想实现什么?你想实现什么?你想实现什么?这只适用于特定模型,而不是所有模型。这只适用于特定模型,而不是所有模型。这只适用于特定模型,而不是所有模型。这只适用于特定模型,不适用于所有车型。这只适用于特定车型,不适用于所有车型。