的RenderPartial的ViewDataDictionar

的RenderPartial的ViewDataDictionar

本文介绍了asp.net MVC RC1的RenderPartial的ViewDataDictionary的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用从母版页传递的ViewData 对象视图用户控件的ViewDataDictionary

I'm trying to pass a ViewData object from a master page to a view user control using the ViewDataDictionary.

问题是的ViewDataDictionary 不是在视图中的用户控件无论怎样我尝试返回任何值。

The problem is the ViewDataDictionary is not returning any values in the view user control whichever way I try it.

样品code下面是使用匿名对象只是为了演示,虽然没有这种方法或传递的ViewData 对象的工作。

The sample code below is using an anonymous object just for demonstration although neither this method or passing a ViewData object works.

以下是的RenderPartial 辅助方法,我试图使用方法:

Following is the RenderPartial helper method I'm trying to use:

<% Html.RenderPartial("/Views/Project/Projects.ascx", ViewData.Eval("Projects"), new ViewDataDictionary(new { Test = "Mark" })); %>

在我看来,用户控制我做到以下几点:

and in my view user control i do the following:

<%= Html.Encode(ViewData["Test"]) %>

为什么这个不返回任何东西?

Why does this not return anything?

感谢您的帮助。

编辑:

我能够通过,并没有任何问题访问强类型​​的模型。它的的ViewDataDictionary 我想要使用传递说只是模型之外的单个值...

I'm able to pass and access the strongly typed model without any problems. it's the ViewDataDictionary which I'm trying to use to pass say just a single value outside of the model...

推荐答案

你试过:

<% Html.RenderPartial("~/Views/Project/Projects.ascx", ViewData); %>

也有你验证计算机[测试]在ViewData的你传递之前?还要注意的是通过你的ViewData到部分控制,它保持模式,同样是重要的,当。

Also have you verified ViewData["Test"] is in the ViewData before you are passing it? Also note that when passing your ViewData to a Partial Control that it is important to keep the Model the same.

尼克

这篇关于asp.net MVC RC1的RenderPartial的ViewDataDictionary的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 00:43