ASP.NET MVC的ViewData(使用指数) [英] ASP.NET MVC ViewData (using indices)

查看:167
本文介绍了ASP.NET MVC的ViewData(使用指数)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不得不使用ASP.NET MVC preVIEW 3(从preVIEW 2溶液升级),使用非类型化ViewMasterPage像这样一个有效的解决方案:

I had a working solution using ASP.NET MVC Preview 3 (was upgraded from a Preview 2 solution) that uses an untyped ViewMasterPage like so:

public partial class Home : ViewMasterPage

在Home.Master有一个显示的语句是这样的:

On Home.Master there is a display statement like this:

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

然而,在团队的开发人员只需更改为preVIEW 4。

However, a developer on the team just changed the assembly references to Preview 4.

在此之后,code将不再填充的ViewData与像上述索引值

Following this, the code will no longer populate ViewData with indexed values like the above.

相反,计算机[通用]为空。

Instead, ViewData["Generic"] is null.

根据这个问题,ViewData.Eval(通用)的作品,并ViewData.Model也是填充正确。

As per this question, ViewData.Eval("Generic") works, and ViewData.Model is also populated correctly.

但是,这个方案没有使用页打印纸等等的原因是因为它是一种旧式的解决方案。因此,它是不切实际的通过这个相当大的解决方案,并更新所有的.aspx页面(尤其是因为编译器没有检测到这种东西)。

However, the reason this solution isn't using typed pages etc. is because it is kind of a legacy solution. As such, it is impractical to go through this fairly large solution and update all .aspx pages (especially as the compiler doesn't detect this sort of stuff).

我曾尝试通过删除引用,然后在项目中的'bin文件夹添加到preVIEW 3集的引用恢复的组件。这并没有改变任何东西。我甚至试图恢复该项目文件到一个较早的版本,仍然似乎没有解决问题。

I have tried reverting the assemblies by removing the reference and then adding a reference to the Preview 3 assembly in the 'bin' folder of the project. This did not change anything. I have even tried reverting the Project file to an earlier version and that still did not seem to fix the problem.

我必须使用继续工作相同的技术,其他解决方案。

I have other solutions using the same technique that continue to work.

你有什么可以建议以为什么这次却突然停止工作,我怎么可能去修复它(在正确的方向任何暗示将AP preciated)?

Is there anything you can suggest as to why this has suddenly stopped working and how I might go about fixing it (any hint in the right direction would be appreciated)?

推荐答案

我们所做的改变,因为我们希望有点对称的[]索引。的eval()方法使用反射,并期待到模型来检索值。索引只着眼于直接添加到字典中的项目。

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.

这篇关于ASP.NET MVC的ViewData(使用指数)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆