是什么导致MissingMethodException

时间:2016-03-02 16:41:13

标签: c# asp.net-mvc asp.net-mvc-4 razor

在MVC / ASP.NET视图中导致MissingMethodException的原因是什么?

今天遇到一个奇怪的问题。在我的视图模型中,我有一个属性,其签名我改变了。它最初返回IEnumerable<Thing>

public IEnumerable<OtherThing> Things
{
    get
    {
        // Code goes here …
    }
}

...我将返回类型更改为IEnumerable<OtherThing>

public IEnumerable<OtherThing> Things
{
    get
    {
        // Code goes here …
    }
}

编辑一切都很好,花花公子。当我加载访问Things的页面时,问题浮出水面。具体来说,我通过MissingMethodException在我通过@Html.RenderPartial()呈现的部分视图中获得了// Inside my partial view @foreach (var thing in Model.Things) { // Rest of view code … } 引起的YSOD:

MissingMethodException

违规代码是foreach循环。 public IEnumerable<Thing> Things抱怨它正在寻找签名public IEnumerable<OtherThing> Things,但却找到了MissingMethodException

经过多次挣扎和困惑,我在局部视图中键入了一些无意义,删除了无意义,并重新保存了文件。瞧。 IEnumerable<Thing>走了。

我解决了这个问题,但我觉得自己被抢走了。为什么视图期待var?这与var有关吗? IEnumerable<Thing>在视图中缓存为{{1}}吗?如果是这样,Razor部分视图是如何缓存的?在哪里?

任何见解都将受到赞赏。

0 个答案:

没有答案
相关问题