Note that there are some explanatory texts on larger screens.

plurals
  1. POASP.NET MVC: The model item passed into the dictionary is of type 'ClassA', but this dictionary requires a model item of type 'ClassA'
    primarykey
    data
    text
    <p>I'm getting a peculiar exception using the Html.RenderPartial method. ASP.NET MVC seems to be unable to an object of type ClassA to an object of type ClassA. I was wondering if anyone knows what's going on.</p> <p>Here's a little more background info. I'm having the following hierarchy in place:</p> <pre><code>public interface IInterface { string Name { get; } } public class ClassA : IInterface { public string Name { get { return "ClassA "; } } } </code></pre> <p>Using these two in a view:</p> <pre><code>&lt;%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage&lt;IEnumerable&lt;IInterface&gt;&gt;" %&gt; &lt;asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server"&gt; &lt;% foreach (IInterface item in Model) { Html.RenderPartial(string.Concat(item.Name, "UserControl"), item); } %&gt; &lt;/asp:Content&gt; </code></pre> <p>And having a UserControl named ClassAUserControl with this header:</p> <pre><code>&lt;%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl&lt;ClassA&gt;" %&gt; </code></pre> <p>Edit: TypeHelpers.IsCompatibleObject(Object value) decides that the two types are different:</p> <pre><code>public static bool IsCompatibleObject&lt;T&gt;(object value) { return ((value is T) || ((value == null) &amp;&amp; TypeAllowsNullValue(typeof(T)))); } </code></pre> <p>In the above case T is ClassA and the type of value is ClassA. That really makes me wonder why 'value is T' fails...</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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