[ACCEPTED]-asp.net MVC RC1 RenderPartial ViewDataDictionary-asp.net-mvc
This is the neatest way I've seen to do 3 this:
<% Html.RenderPartial("/Views/Project/Projects.ascx", Model, new ViewDataDictionary{{"key","value"}});%>
It may be a little hackish, but it 2 let's you send the model through AND some 1 extra data.
Don't know if anyone still cares but I used 5 a KeyValuePair for the ViewDataDictionary.
<% Html.RenderPartial("ItemRow", item, new ViewDataDictionary{
new KeyValuePair<string, object>("url", url),
new KeyValuePair<string, object>("count", count),
new KeyValuePair<string, object>("className", className)
}); %>
This 4 way you can write everything in one statement. The 3 KVPs can be accessed in the view by:
<%= ViewData["url"] %>
<%= ViewData["count"] %>
<%= ViewData["className"] %>
While 2 what I passed through the model can be accessed 1 through Model.*
I'm using the RTM version of ASP.Net MVC, but 4 with:
<% Html.RenderPartial("~/Views/Project/Projects.ascx", new ViewDataDictionary(new {Key = "Some value"})); %>
Try the following when referencing 3 the value in your partial view:
<%= ViewData.Eval("Key") %>
That seems 2 to have done the trick for me. It will also 1 work if you just do this:
<% Html.RenderPartial("~/Views/Project/Projects.ascx", new {Key = "Some value"}); %>
Hope this helps.
Have you tried:
<% Html.RenderPartial("~/Views/Project/Projects.ascx", ViewData); %>
Also have you verified ViewData["Test"] is 4 in the ViewData before you are passing it? Also 3 note that when passing your ViewData to 2 a Partial Control that it is important to 1 keep the Model the same.
Nick
In your main view:
<% Html.RenderPartial("~/Views/Project/Projects.ascx", ViewData["Projects"]); %>
Either in you controller 3 or your main view:
ViewData["Test"] = "Mark";
If you don't specify a 2 model or view data dictionary in RenderPartail, it 1 uses the ones from the containing view.
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.