I’m just begin upgrade my asp.net site from Webform to MVC 2. So far it’s more clear and lighter than Webform. I’m stucking on the part of rending an User Control in different actions.
My User Control named Banner.ascx is placed in Site.Master. This Banner.ascx get url from DataView["BannerUrl"] which is set in HomeController > Index action. This will run OK when I point URL to /Home/Index. Now I want this Banner.ascx control get DataView only from HomeController > Index whatever action I’m pointing to, for example when point URL to /Article/Detail/1 I want the Banner.ascx run action Index of HomeConttroller to get DataView["BannerUrl"]
Any response is appreciated. Thanks in advance.
You can call the MVC Controller the same way you would call any other server-side code. You can access the registered
IControllerFactoryinstance viaControllerBuilder.GetControllerFactory(). Then you can use the controller factory to get an initialized instance of theIControllerinstance by passing it the route values in theRouteDataof theRequestContextparameter (these would becontroller = "Home"andaction = "Index".IController.Execute()will then execute the Action the same way that the MVC life cycle would if it received a request.