根接口属性通过在HTML辅助父接口无法访问 [英] Root interface property not accessible via parent interface in Html helper

查看:128
本文介绍了根接口属性通过在HTML辅助父接口无法访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我觉得我失去了一些东西基本在这里。

I feel like I am missing something basic here.

我有2个接口。一个叫IIdentifiable它指定id属性的存在。第二个确实可以是任意的也可识别。见下面code。

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; }
}

的问题:

在使用Html.HiddenFor(或任何其他辅助方法),该模型是强类型的IPerson界面,我访问了IIdentifiable接口的属性时,会得到一个错误。我可以用拉姆达EX pression和访问模型时访问和直接违背Model.Id,但不显示在IIdentifiable性能数据的方式。

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 display 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.

我得到的错误是财产* .IPerson.Id找不到。

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

这似乎只能是这样使用的剃刀视图引擎的时候。我知道这是用ASP.NET MVC 2的工作和的WebForms视图引擎。使用的WebForms视图引擎但我还没有尝试过在ASP.NET MVC 3。

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.

推荐答案

是的,<一个href="http://connect.microsoft.com/VisualStudio/feedback/details/636341/modelmetadata-fromlambdaex$p$pssion-has-changed-in-asp-net-mvc-3-rtm"相对=nofollow>我打开一票把这个以微软的注意。另请参阅<一href="http://stackoverflow.com/questions/4702483/asp-net-mvc-3-htmlhelper-exception-does-not-recognize-modelmetadata-on-inherited/4702788">this相关的问题。

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

这篇关于根接口属性通过在HTML辅助父接口无法访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆