Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>There has been a breaking change/bug in ASP.NET MVC 3 in the <code>System.Web.Mvc.ModelMetadata. FromLambdaExpression</code> method which explains the exception you are getting:</p> <p>ASP.NET MVC 2.0:</p> <pre><code>... case ExpressionType.MemberAccess: { MemberExpression body = (MemberExpression) expression.Body; propertyName = (body.Member is PropertyInfo) ? body.Member.Name : null; containerType = body.Member.DeclaringType; flag = true; break; } ... </code></pre> <p>ASP.NET MVC 3.0</p> <pre><code>... case ExpressionType.MemberAccess: { MemberExpression body = (MemberExpression) expression.Body; propertyName = (body.Member is PropertyInfo) ? body.Member.Name : null; containerType = body.Expression.Type; flag = true; break; } ... </code></pre> <p>Notice how the <code>containerType</code> variable is assigned a different value. So in your case in ASP.NET MVC 2.0 it was assigned the value of <code>IOwned</code> which is the correct declaring type of the <code>AuthorId</code> property whereas in ASP.NET MVC 3.0 it is assigned to <code>IActivity</code> and later when the framework tries to find the property it crashes.</p> <p>That's the cause. As far as the resolution is concerned I would wait for some official statement from Microsoft. I can't find any relevant information about this in the Release Notes document. Is it a bug or some <em>feature</em> which needs to be workarounded here?</p> <p>For now you could either use the non-strongly typed <code>Html.Hidden("AuthorId")</code> helper or specify <code>IOwned</code> as type for your control (I know both suck).</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload