R – How to pass data from a controller to a strongly typed user control in asp.net mvc

asp.net-mvcmaster-pagesuser-controls

I have a strongly typed User Control which should show a user's orders on all pages, it's included in a master page. I have an OrdersController which can give me the current orders and is used at other locations.

How do I tell the UserControl in the Master Page that it should get its Data from that specific Controller / Controller Action? I'd like to access the viewdata within the ascx just as I would in a normal View.

Best Answer

Pass model and ViewData as parameters to the RenderPartial method. It will make model and view data accessible as if you were in the parent view page.

<% Html.RenderPartial ( "../Shared/HRMasterData/DependentPersonDossiers",
  ViewData.Model, ViewData ); %>