asp.net MVC RC1 RenderPartial ViewDataDictionary

Posted by Mark79 on Stack Overflow See other posts from Stack Overflow or by Mark79
Published on 2009-01-30T12:25:14Z Indexed on 2010/04/12 2:33 UTC
Read the original article Hit count: 891

Filed under:
|
|

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

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

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

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?

Thanks for your help.

EDIT:

I'm able to pass and access the stronlgy 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..

© Stack Overflow or respective owner

Related posts about asp.net-mvc

Related posts about .NET