Luk*_*uke 2 asp.net-mvc inheritance modelbinders
我有一个关于ASP.NET MVC中的ModelBinding的问题(我正在使用MVC 2预览2)与继承相关.
假设我有以下接口/类:
interface IBase
class Base : IBase
interface IChild
class Child: Base, IChild
Run Code Online (Sandbox Code Playgroud)
我有一个自定义模型绑定器BaseModelBinder.
以下工作正常:
ModelBinders.Binders[typeof(Child)] = new BaseModelBinder();
ModelBinders.Binders[typeof(IChild)] = new BaseModelBinder();
Run Code Online (Sandbox Code Playgroud)
以下不起作用(绑定类型为Child的on对象):
ModelBinders.Binders[typeof(Base)] = new BaseModelBinder();
ModelBinders.Binders[typeof(IBase)] = new BaseModelBinder();
Run Code Online (Sandbox Code Playgroud)
有没有办法让基类的模型绑定器适用于所有继承的类?我真的不想为每个可能的继承类手动输入内容.
此外,如果可能,是否有办法覆盖特定继承类的模型绑定器?说我有这个工作,但我需要一个特定的Child2模型绑定器.
提前致谢.
| 归档时间: |
|
| 查看次数: |
2288 次 |
| 最近记录: |