3

Code in partial 1 file:

 @Html.Partial("Partial2", 50)

Code in partial 2 file:

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

Does this really require me to create a new controller?

hutchonoid
  • 32,257
  • 14
  • 95
  • 102
Alex
  • 812
  • 1
  • 8
  • 19

2 Answers2

5

Partial and RenderPartial don't require a controller. Action and RenderAction require a controller.

So your code in partial 2 should be:

@model int

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

Also a good read is Html.Partial vs Html.RenderPartial & Html.Action vs Html.RenderAction

Community
  • 1
  • 1
Erik Philips
  • 51,408
  • 11
  • 123
  • 146
2

No, just add the model directive in Partial 2:

@model int
@if(Model == 50)
{
     <div>50 Was Passed In</div>
}
hutchonoid
  • 32,257
  • 14
  • 95
  • 102