The easiest way to transfer data to a partial view from a partial view

Code in partial 1 file:

 @Html.Partial("Partial2", 50)

Code in partial file 2:

@if(passed in parameter == 50)
{
     <div>50 Was Passed In</div>
}

Does this really require me to create a new controller?

+3
source share
2 answers

Partial and RenderPartial no controller required. Action and RenderAction require a controller.

So, your code in part 2 should be:

@model int

@if(Model == 50)
{
 <div>50 Was Passed In</div>
}

Also a good reading of Html.Partial vs Html.RenderPartial and Html.Action vs Html.RenderAction

+5
source

No, just add the model directive to Partial 2:

@model int
@if(Model == 50)
{
     <div>50 Was Passed In</div>
}
+2
source

All Articles