6/22/2018 - 1:18 PM

Passing Data to Partial View

You simply have some value in your main view that you want to access in a 
partial being rendered in that view.

If you just render a partial with just the partial name:

It will actually pass your model as an implicit parameter, the same as if you were to call:

@Html.Partial("_SomePartial", Model)
Now, in order for your partial to actually be able to use this, though, 
it too needs to have a defined model, for example:

@model Namespace.To.Your.Model

@Html.Action("MemberProfile", "Member", new { id = Model.Id })
Alternatively, if you're dealing with a value that's not on your view's model 
(it's in the ViewBag or a value generated in the view itself somehow, 
then you can pass a ViewDataDictionary

@Html.Partial("_SomePartial", new ViewDataDictionary { { "id", someInteger } });
And then:

@Html.Action("MemberProfile", "Member", new { id = ViewData["id"] })
As with the model, Razor will implicitly pass your partial the view's ViewData by default, 
so if you had ViewBag.Id in your view, then you can reference the same thing in your partial.