Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing a string into a partial view in MVC4

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.

like image 238
RobVious Avatar asked Feb 18 '13 21:02

RobVious


People also ask

Can we use model in partial view?

Partial Views can use the Page Model for their data whereas Child Actions use independent data from the Controller. Editor/Display templates pass items from the model to the system but can be overridden by user partial views.


1 Answers

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

like image 119
Dave Alperovich Avatar answered Oct 18 '22 00:10

Dave Alperovich