Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net 无法通过Html帮助程序中的父接口访问根接口属性_.net_Asp.net Mvc 3_Razor - Fatal编程技术网

.net 无法通过Html帮助程序中的父接口访问根接口属性

.net 无法通过Html帮助程序中的父接口访问根接口属性,.net,asp.net-mvc-3,razor,.net,Asp.net Mvc 3,Razor,我觉得我错过了一些基本的东西 我有两个接口。其中一个称为IIIdentifiable,它指定Id属性的存在。第二种可能是任何可以识别的东西。请参阅下面的代码 public interface IIdentifiable { Guid Id { get; set; } } public interface IPerson : IIdentifiable { string Name { get; set; } } 问题: 当使用Html.HiddenFor(或任何其他helper方

我觉得我错过了一些基本的东西

我有两个接口。其中一个称为IIIdentifiable,它指定Id属性的存在。第二种可能是任何可以识别的东西。请参阅下面的代码

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

当使用Html.HiddenFor(或任何其他helper方法)并且模型强类型化到IPerson接口时,我在访问IIIdentifiable接口的属性时出错。我可以通过直接访问Model.Id来访问和显示IIIdentifiable属性中的数据,但在使用lambda表达式并以这种方式访问模型时则不行

我得到的错误是“找不到属性*.IPerson.Id”


这似乎只有在使用Razor视图引擎时才会出现。我知道这是使用ASP.NETMVC2和WebForms视图引擎实现的。我还没有使用WebForms视图引擎在ASP.NET MVC 3上尝试过它。

是的,微软注意到了,打开了一张罚单。另请看。

当其他人和我有同样的问题时,我总是感觉不那么疯狂。正如有人在Darin提供的链接中所说,这是一个解决方案或现在:

<%: Html.HiddenFor(m => (m as IIdentifiable).Id) %>
(m作为可识别的).Id)%>

谢谢!我找了这么多,但没找到。如果我没有得到答案,我今天就要深入研究这个问题。谢谢。现在让我们希望微软能解决这个问题。