RenderPartial在Dev上呈现但在Production服务器上失败

时间:2011-04-11 22:28:05

标签: asp.net-mvc-3 razor renderpartial

我从'user'存在的主视图中调用RenderPartial:

@{Html.RenderPartial("DisplayTemplates/uInfo", user);}

在我的开发机器上运行,但生产服务器正在抛出运行时错误:

未找到部分视图'DisplayTemplates / uInfo'或视图引擎不支持搜索的位置。搜索了以下位置:...

搜索了以下位置:

~/Views/Account/DisplayTemplates/uInfo.aspx
~/Views/Account/DisplayTemplates/uInfo.ascx
~/Views/Shared/DisplayTemplates/uInfo.aspx
~/Views/Shared/DisplayTemplates/uInfo.ascx
~/Views/Account/DisplayTemplates/uInfo.cshtml
~/Views/Account/DisplayTemplates/uInfo.vbhtml
~/Views/Shared/DisplayTemplates/uInfo.cshtml
~/Views/Shared/DisplayTemplates/uInfo.vbhtml

列出了我的文件_ - Shared / DisplayTemplates / uInfo.cshtml并在本地工作。

如果它相关 - 我正在利用Razor和遗留.aspx视图之间自由切换的自由。最初担心两者混合的可能并发症,但到目前为止,我所尝试过的一切都有效。

THX

1 个答案:

答案 0 :(得分:0)

不应该是:

@Html.DisplayFor(model => model.User)

如果model.User的类型为uInfo,MVC默认会查找DisplayTemplates文件夹并找到uInfo.cshtml。这就是MVC惯例。

您不应使用RenderPartial呈现显示模板。

如果您想要部分视图,请执行以下操作:

@Html.Partial("SomePartial", user)

尽管如此,我同意你看到的行为很奇怪,这并不能真正回答你的问题 - 但首先要尝试并遵守MVC惯例。