We are having an issue with the Razor view engine not resolving nested interfaces. Sample code:
public interface IDto
{
Guid Id {get;set;}
}
public interface IUserDto: IDto
{
string Username {get;set;}
}
//The view
@model IUserDto
//pukes on this line
@Html.DisplayFor(u => u.Id)
Should we be using concrete models on our views? Is the Razor view engine not capable of using multiple interfaces per model?
This was a change in ASP.NET MVC 3 that I already brought to the attention of Microsoft (this scenario worked on ASP.NET MVC 1 and 2).
Here's their official answer:
Now to the point
Not necessary. You could still use interfaces on your main views, but then have editor/display templates with concrete types. At runtime based on the actual type of the view model the framework will pick the correct template where you will have the concrete type and it will resolve the Id property.
Another possibility is to use abstract classes instead of interfaces (beurk I know :-) typically Microsoftish)