Pass Additional ViewData to a Strongly-Typed Partial View
Solution 1:
RenderPartial takes another parameter that is simply a ViewDataDictionary. You're almost there, just call it like this:
Html.RenderPartial(
"ProductImageForm",
image,
new ViewDataDictionary { { "index", index } }
);
Note that this will override the default ViewData that all your other Views have by default. If you are adding anything to ViewData, it will not be in this new dictionary that you're passing to your partial view.
Solution 2:
To extend on what womp posted, you can pass new View Data while retaining the existing View Data if you use the constructor overload of the ViewDataDictionary
like so:
Html.RenderPartial(
"ProductImageForm",
image,
new ViewDataDictionary(this.ViewData) { { "index", index } }
);
Solution 3:
@Html.Partial("_Header", new ViewDataDictionary { { "HeaderName", "User Management" }, { "TitleName", "List Of Users" } })
or
@{Html.RenderPartial("_Header", new ViewDataDictionary { { "HeaderName", "User Management" }, { "TitleName", "List Of Users" } });}
Partial Page(_Header):
<div class="row titleBlock">
<h1>@ViewData["HeaderName"].ToString()</h1>
<h5>@ViewData["TitleName"].ToString()</h5>
</div>
Solution 4:
I think this should work no?
ViewData["currentIndex"] = index;