I am getting an odd error from an MVC3 webforms view that has stumped me.
Setup: I have two interfaces defined:
public interface IDbObject {
int Id { get; set; }
string Name { get; set; }
}
public interface IAutomobile : IDbObject {
string VIN { get; set; }
}
public class Automobile : IAutomobile {
public int Id { get; set; }
public string Name { get; set; }
public string VIN { get; set; }
}
My view is a strongly-typed view: System.Web.Mvc.ViewPage<IAutomobile>
and my contro开发者_JS百科ller
When I attempt to use a EditorFor on the Name property
<%= Html.EditorFor(a => a.Name) %>
I get an exception: System.ArgumentException: The property IAutomobile.Name could not be found.
However, if I comment out this statement, my EditorFor on the VIN continues to function properly:
<%= Html.EditorFor(a => a.VIN) %>
Is there something I'm missing?
This sounds like a limitation of EditorFor
. Perhaps it's not smart enough to check implemented interfaces for properties.
Solution found:
I re-implemented the 'Name' property on the IAutomobile interface:
public interface IAutomobile : IDbObject {
new string Name { get; set; }
string VIN { get; set; }
}
I made no changes to my concrete class, and the EditorFor method was able to work with the Name property.
精彩评论