7

When I'm in a View and I call @Html.RenderPartial("MyPartialView", MyObject) Can I set it up so that this partial view has a controller which is called when RenderPartial gets called?

tereško
  • 57,247
  • 24
  • 95
  • 149
dev.e.loper
  • 35,011
  • 72
  • 156
  • 240

3 Answers3

9

Probably it will be better to use the RenderAction instead of the RenderPartial

Mikhail
  • 9,058
  • 4
  • 32
  • 49
  • Yes. It looks like I need to use RenderAction instead. Also found this helpful http://stackoverflow.com/questions/3968664/asp-net-mvc-2-0-difference-between-renderpartial-and-renderaction – dev.e.loper Jul 05 '11 at 21:00
1

You should gather all data necessary for the partial in the current controller action (which may use methods shared across other controllers and actions).

If you really want a partial to be rendered using its own controller/action then consider loading it via AJAX with a separate request.

Wizard of Ogz
  • 12,363
  • 2
  • 40
  • 43
0

In MVC, although controllers know about views, the reverse is not true.

Views are just means to render some data (a model or a viewModel) but they are not related to a controller or an action.

Hector Correa
  • 25,772
  • 7
  • 56
  • 70