views:

75

answers:

2

I'm porting an application from WebForms to MVC.

I have a WebForms UserControl that is used throughout the site and which contains presentational and business logic, and in particular some 'initizliation' logic (in the Page_Load)

My understanding of MVC UerControls is that they have no dedicated controller and thus contain no logic, and the logic is added to the controller of the viewpage to which the UserControl is added.

Now, I don;t want to have to write the initialization logic in my ViewPage, as this UserControl appears on several pages, thus duplication of logic.

I don't think I can user a MasterPage, as the UserControl can be rendered either vertically to the left of the page or hozontally at the top of the page depending on what page it is. This would require 2 MasterPage's, and again duplication of logic.

Do I have any other options?

A: 

Bleh, I guess I should do it properly and pass in a object via my controller's viewdata rather than hacky-slash it.

Jaimal Chohan
Resolved this by doing it properly and creating an object to enscapulate my view logic. Much cleaner now.
Jaimal Chohan
+1  A: 

This is a good case to use the RenderAction html helper. Much better, grab the Microsoft MVC futures and use the RenderAction method. Basically it lets you call a controller action within a view, which is alot more like how UserControls work than RenderPartial.

Wyatt Barnett