我正在从MVC区域之外的项目中提取一些代码到HttpHandler,同时重用尽可能多的代码。
为了方便起见,我想将发布的数据转换为已在Controller中使用的相同模型。
所以,现在我正在寻找逻辑MVC在封面下使用神奇地将发布的数据转换为模型,但经过几次反编译尝试后我无法找到它。
有人能指出我正确的方向吗?
谢谢!
SaphuA:基本上,我想输入HttpContext和目标Model的类型,并让helper方法执行其余的映射。
I am extracting some code from a project outside of the MVC-area to a HttpHandler while reusing as much code as possible.
To make things easy I would like to convert the posted data to the same Model that was already used in the Controller.
So, now I am looking for the logic MVC is using under the covers to magically convert posted data to a Model, but after several decompile attempts I am unable to find this.
Could anyone point me in the right direction?
Thanks!
SaphuA: Basically, I want to input the HttpContext and the type of the target Model and have the helper method do the rest of the mapping.
最满意答案
正如Eric所说,只是扩展DefaultModelBinder.cs
默认模型绑定器在这里
从控制器动作调用程序调用模型绑定器
这里总体流程很好地概述了,所以只需滚动查看控制器动作调用程序的调用位置。
如果您想围绕绑定器的实现启动一些单元测试,请查看MVC源测试
使用github镜像,因为codeplex不支持行号链接:-)
HTH
As Eric says, just extent the DefaultModelBinder.cs
The default model binder is here
The model binder is called from the controller action invoker
The overall flow is nicely outlined here so just scroll to check where the controller action invoker is called.
If you want to spin up some unit tests around your implementation of the binder, check out the MVC source tests
Using the github mirror because codeplex does not support line number linking yet :-)
HTH
更多推荐
发布评论