ASP.net MVC v2 – 调试模型绑定问题 – BUG?
|
我试图调试为什么MVC在一个给定的情况下没有正确绑定我有一些困难我有… 基本上,我有我的操作接收一个复杂的对象,它又有一个复杂的子对象 – Activity.Location.State(其中Activity是操作期望的复杂对象,Location是一个复杂的子对象,State只是一个字符串) 。 现在我设立了一个测试项目,据我所知,在我的实际项目中,绑定到活动工作,但不是位置…通过在Locaiton属性中设置断点,我可以告诉MVC正在从Activity中检索复杂的Location对象,但是它没有设置任何属性… 我正在尝试调试问题,但是我需要访问MVC v2预览2个符号,我似乎无法追踪…我想看看它实际在做什么,一旦它拉出位置对象(对于一些原因我认为它可能在内部失败,但吞咽异常)。 关于我在这里可以做什么的任何想法 干杯 更新: 好的,我做了什么建议并直接参考MVC项目… 我发现这个问题,有一个很小的区别,我忽略了…因为我结果我发现,当涉及到模型绑定时,MVC目前不支持多层次的INTERFACE继承…见下面的… //MODEL
public class Location : ILocation
{
...
}
public interface ILocation : ILocationCore
{
...
}
public interface ILocationCore //In my sample I didn't have this second level interface
{
...
//MVC doesn't find any of these properties
...
}
public class Activity : IActivity
{
...
}
public interface IActivity : IActivityCore
{
ILocation Location { get; set; } //MVC finds this and reads its meta type as an ILocation
//Also the implementation of this Location within Activity will always return a instance - our IoC takes care of that,so MVC should never have to create the instance
}
public interface IActivityCore
{
...
}
//CONTROLLER
public ActionResult Create(Activity activity)
{
}
因此,我发现MVC找到位置并将其类型读取为一个ILocation,但是当DefaultModelBinder中运行GetModelProperties时,会发生以下情况: protected virtual PropertyDescriptorCollection GetModelProperties(ControllerContext controllerContext,ModelBindingContext bindingContext) {
return GetTypeDescriptor(controllerContext,bindingContext).GetProperties();
//This return no properties
}
protected virtual ICustomTypeDescriptor GetTypeDescriptor(ControllerContext controllerContext,ModelBindingContext bindingContext) {
return new AssociatedMetadataTypeTypeDescriptionProvider(bindingContext.ModelType).GetTypeDescriptor(bindingContext.ModelType);
//bindingContext.ModelType - is ILocation
}
因此,我现在假设TypeDescriptionProvider不支持这种继承风格,我很惊讶。另外看v1版本,它看起来像是用v2引入的 – 但是v1可能无法支持我正在努力做的事情。 我不会说这真的是一个错误,但我尝试用具体的类替换了接口,并且工作正常。因此,行为并不是我期望的,并且有点不一致。 有什么想法吗???我会认为这种遗产不是相当标准的,但会经常发生足够的照顾。谢谢回复。 干杯 解决方法结果是由于接口继承如何工作,这种行为是设计的。接口不定义实现,因此ILocation不会“继承”ILocationSource的属性。相反,ILocation仅定义具体实现必须实现的内容。有关详细信息,包括定义此行为的CLI(公共语言基础结构)规范的部分,请查看:http://haacked.com/archive/2009/11/10/interface-inheritance-esoterica.aspx (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- asp.net-mvc – 如何使用EditorForModel()来装饰我的ASP.NE
- asp.net-mvc – 服务层是否可以访问HttpContext?
- asp.net-mvc-3 – 是否有自动方式在MVC中查找未使用的视图?
- asp.net-mvc-3 – insert命令需要插入数据绑定设置Kendo Gr
- 如何排序. .NET中的resx(资源文件)
- IIS 7中的应用程序池不显示.NET Framework 3.5
- ASP.NET 4的IIS和服务器操作系统要求
- .net – 实体单位工作和存储库模式的好处
- asp.net-mvc – 不显眼的验证不适用于Ajax.BeginForm
- 强烈推荐的一个工具ReSharper
- asp.net-mvc – 在MVC文件上传中Request.files为
- asp.net-mvc – 为什么我的View不包括_Layout.cs
- ASP.NET的智能卡身份验证
- dependency-injection – Ninject:构造函数参数
- 使用ASP.NET MVC 3助手的标题属性的渲染跨度标签
- asp.net – Microsoft WebMatrix和Visual Studio
- 我如何在ASP.Net Web窗体中模拟/伪造会话对象?
- ASP.NET MVC 4 AJAX提交表单不工作
- asp.net – 菜单控件生成的js导致Web窗体中的Sys
- asp.net-core – ASP .NET Core默认语言总是英文
