我觉得我在这里缺少一些基本的东西。
我有2个接口(interface)。一种称为 IIdentifiable,它指定 Id 属性的存在。第二个实际上可以是任何可识别的东西。请参阅下面的代码。
public interface IIdentifiable
{
Guid Id { get; set; }
}
public interface IPerson : IIdentifiable
{
string Name { get; set; }
}
问题:
当使用 Html.HiddenFor(或任何其他帮助方法)并且模型被强类型化到 IPerson 接口(interface)时,访问 IIdentifiable 接口(interface)的属性时出现错误。我可以通过直接针对 Model.Id 访问和显示 IIdentifiable 属性中的数据,但在使用 lambda 表达式并以这种方式访问模型时不能。
我得到的错误是“找不到属性 *.IPerson.Id”。
只有在使用 Razor View 引擎时才会出现这种情况。我知道这是使用 ASP.NET MVC 2 和 WebForms View 引擎工作的。我还没有在使用 WebForms View 引擎的 ASP.NET MVC 3 上尝试过它。
最佳答案
是的,I have brought this通过开票引起 Microsoft 的注意。另见 this related question .
关于.net - 无法通过 Html 帮助程序中的父接口(interface)访问根接口(interface)属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4741442/