> In general, when you use Html.Partial;
Html.Partial("partialViewName");
The model that is dispatched for parentView can be used for in componentViewName. In addition, the ViewData that is dispatched for parentView can also be used for a partial ViewName.
> As a special case when you use Html.Partial and want to send Model.
Html.Partial("partialViewName", newModel);
You cannot get to the model that was submitted for parentView. Therefore, from today on, the Model that is active in partalViewName is newModel. The ViewData that is dispatched for parentView can also be used for a partial ViewName.
> As a special case when you use Html.Partial and want to send ViewDataDictionary ..
The model that is submitted for parentView can also be used for partial viewing.
I AM.
@Html.Partial("partialViewName", new ViewDataDictionary { { "key", value }, { "key2", value2 } })
Here, the ViewData that was sent for parentView is overwritten with the 'new ViewDataDictionary'.
Here, if there is a ViewBag for parentView, you will not be able to achieve this if you write code like the one above.
II.
ViewDataDictionary viewDataDictionary = new ViewDataDictionary(); viewDataDictionary.Add("key", value); viewDataDictionary.Add("key2", value2); @Html.Partial("partialViewName", viewDataDictionary)
This usage is the same as the first (s).
III.
ViewDataDictionary viewDataDictionary = ViewData; //If you use this code block, ViewBag which is sent for parent View is not lost. viewDataDictionary.Add("key", value); viewDataDictionary.Add("key2", value2); @Html.Partial("partialViewName", viewDataDictionary)
With this block of code, you can access the ViewData and ViewBag that are sent for parentView in partalViewName.