开发者

Root interface property not accessible via parent interface in Html helper

I feel like I am missing something basic here.

I have 2 interfaces. One is called IIdentifiable which specifies the existence of an Id property. The second can really be anything that is also identifiable. See code below.

public interface IIdentifiable
{
    Guid Id { get; set; }
}
public interface IPerson : IIdentifiable
{
    string Name { get; set; }
}

The problem:

When using the Html.HiddenFor (or any other helper method) and the model is strongly typed to the IPerson interface, I get an error when accessing the properties of the IIdentifiable interface. I can access and displa开发者_StackOverflow中文版y the data in the IIdentifiable properties by going directly against Model.Id but not when using the lambda expression and accessing the model that way.

The error I get is "The property *.IPerson.Id could not be found".

This only seems to be the case when using the Razor view engine. I know this was working using ASP.NET MVC 2 and the WebForms view engine. I haven't tried it on the ASP.NET MVC 3 using the WebForms view engine yet.


Yes, I have brought this to the attention of Microsoft by opening a ticket. Also see this related question.


I always feel less insane when other people have the same problems I do. As someone said in the link Darin provided, this is a work around or now:

<%: Html.HiddenFor(m => (m as IIdentifiable).Id) %>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜