1

我有一个使用 ASP.NET MVC Preview 3(从 Preview 2 解决方案升级)的工作解决方案,它使用无类型的 ViewMasterPage,如下所示:

public partial class Home : ViewMasterPage

在 Home.Master 上有这样的显示语句:

<%= ((GenericViewData)ViewData["Generic"]).Skin %>

但是,团队中的一位开发人员刚刚将程序集引用更改为 Preview 4。

在此之后,代码将不再像上面那样使用索引值填充 ViewData。

相反, ViewData["Generic"] 为空。

根据这个问题, ViewData.Eval("Generic") 有效,并且 ViewData.Model 也正确填充。

然而,这个解决方案不使用打字页面等的原因是因为它是一种遗留解决方案。因此,通过这个相当大的解决方案并更新所有 .aspx 页面是不切实际的(特别是因为编译器没有检测到这种东西)。

我尝试通过删除引用然后在项目的“bin”文件夹中添加对 Preview 3 程序集的引用来还原程序集。这并没有改变什么。我什至尝试将项目文件恢复到早期版本,但这似乎仍然无法解决问题。

我有其他使用相同技术的解决方案可以继续工作。

关于为什么突然停止工作以及我如何修复它(任何正确方向的提示将不胜感激),您有什么建议吗?

4

5 回答 5

1

We made that change because we wanted a bit of symmetry with the [] indexer. The Eval() method uses reflection and looks into the model to retrieve values. The indexer only looks at items directly added to the dictionary.

于 2008-09-18T16:04:29.547 回答
0

我决定用 ViewData.Eval("blah") 替换 ViewData["blah"] 的所有实例。但是,如果可能的话,我想知道这种变化的原因,因为:

  1. 如果它发生在我的其他项目中,能够修复它会很好。
  2. 保留已部署的工作代码而不用这些更改覆盖会很好。
  3. 很高兴知道没有其他我没有注意到的变化。
于 2008-09-15T02:45:26.637 回答
0

你是如何设置视图数据的?这对我有用:

控制器:

ViewData["CategoryName"] = a.Name;

看法:

<%= ViewData["CategoryName"] %>

顺便说一句,我现在在 Preview 5 上。但这已经在 3 和 4 上起作用了......

于 2008-09-15T03:45:53.717 回答
0

回复:瑞奇

当我从控制器调用 View() 方法时,我只是传递了一个对象。

我还注意到,在未更新任何内容的部署服务器上, ViewData.Eval 失败并且 ViewData["index"] 有效。

On my development server ViewData["index"] fails and ViewData.Eval works...

于 2008-09-15T04:02:04.627 回答
0

Yeah, so whatever you pass into the View is accessible in the View as ViewData.Model. But that will be just a good old object if you don't do the strongly typed Views...

于 2008-09-15T14:16:48.067 回答