Reputation: 12915
I'd like to be able to pass a string into my partial view from the calling View - this string will be different depending on the view from which the partial view is rendered. Something like this:
@{ Html.RenderPartial("PartialViews/_BreadcrumbsPartial", "New Item");}
Or
@{ Html.RenderPartial("PartialViews/_BreadcrumbsPartial", Model.Name);}
How can I access this second parameter from within the partial view, since I haven't labeled that parameter? I'd like to avoid passing the whole model in if possible, and just reference that string directly.
Upvotes: 29
Views: 24924
Reputation: 32500
Your Partial Must bind to a string
example, at top place this:
@model string
To access the value in your partial, use @Model
in place of string param
Upvotes: 51
Reputation: 21430
You could use TempData
(or possibly ViewData
) which should be accessible in subsequent views. However, I believe you can also pass variables directly, maybe via query string.
Please see this question as well asp.net mvc parameter from page to a partial view
Upvotes: 0