【发布时间】:2011-06-09 19:17:51
【问题描述】:
升级到 MVC 3 RTM 后,我遇到了以前工作的异常。
这里是场景。我有几个使用相同底层接口 IActivity 和 Iowned 的对象。
IActivity implements IOwned (another interface)
public interface IActivity:IOwned {...}
public interface IOwned
{
int? AuthorId {get;set;}
}
我有一个局部视图,它使用 IActivity 从其他具体局部重用。
这里是Activity Partial的定义。
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<IActivity>" %>
<%: Html.HiddenFor(item => item.AuthorId) %>
但是,它会引发异常。在 ModelMetadata 中找不到 AuthorId。
我猜在以前的版本中它着眼于 IActivity 实现的接口。
除了在所有地方复制类似的界面之外,有什么想法、建议吗?
复制了下面的堆栈跟踪。
[ArgumentException: The property IActivity.AuthorId could not be found.]
System.Web.Mvc.AssociatedMetadataProvider.GetMetadataForProperty(Func`1 modelAccessor, Type containerType, String propertyName) +498313
System.Web.Mvc.ModelMetadata.GetMetadataFromProvider(Func`1 modelAccessor, Type modelType, String propertyName, Type containerType) +101
System.Web.Mvc.ModelMetadata.FromLambdaExpression(Expression`1 expression, ViewDataDictionary`1 viewData) +393
System.Web.Mvc.Html.InputExtensions.HiddenFor(HtmlHelper`1 htmlHelper, Expression`1 expression, IDictionary`2 htmlAttributes) +57
System.Web.Mvc.Html.InputExtensions.HiddenFor(HtmlHelper`1 htmlHelper, Expression`1 expression) +51
ASP.views_shared_activity_ascx.__Render__control1(HtmlTextWriter __w, Control parameterContainer) in c:\Users\...\Documents\Visual Studio 2010\Projects\ngen\trunk\...\Views\Shared\Activity.ascx:3
System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +109
System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +8
System.Web.UI.Control.Render(HtmlTextWriter writer) +10
System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27
System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +100
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +208
System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +8
System.Web.UI.Page.Render(HtmlTextWriter writer) +29
System.Web.Mvc.ViewPage.Render(HtmlTextWriter writer) +43
System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27
System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +100
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3060
【问题讨论】:
-
您是否尝试过单步执行框架代码?
-
不,我还没有逐步完成框架代码。我希望不要;)我认为现在我可以通过切换到 来解决它,但是这看起来像是 FX 恕我直言的一个重大变化。
标签: asp.net asp.net-mvc-3 html-helper modelmetadata