Passing a string into a partial view in MVC4
asp.net, asp.net-mvc, asp.net-mvc-3, asp.net-mvc-4, razor
Solution
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
Problem
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.