3

We're working to convert a site from web forms to MVC. There's a desire to replace the web forms sublayouts with MVC renderings as we go along, until the site is completely converted. I found this article that talks about going both ways with this (MVC layout with web forms sublayouts, or web forms layout with MVC renderings): https://blog.horizontalintegration.com/2015/09/15/mixing-sublayout-with-rendering-webforms-with-mvc-request/

I was wondering if anyone has practical experience with this and has a recommended method? My preference would be to use an MVC layout and include the web forms sublayouts until they're replaced, but I can make a case for going the other way if it's simpler.

3
  • 2
    A number of people have covered mixing the technologies. Check out Reuse your old ASP.NET Web Forms controls in Sitecore MVC and Mixing Sublayout with Rendering – Webforms with MVC request Commented Feb 18, 2017 at 22:42
  • I've done it with some success as well. I've found that trying to keep an MVC set of pages and a Webforms set of pages is the best approach, but Sitecore supports renderings side by side with MVC. As for your specific question, the MVC layout is probably best, but it ultimately doesn't matter in the end. Sitecore triggers all the rendering to be done and then populates the placeholders. Unless you're relying on MVC framework level stuff you should be ok. Commented Feb 18, 2017 at 23:47
  • I've experimented with this method (using the implementation from Hedgehog) a number of years ago. It largely worked fine for simple components but we had difficulty with more complex components with post-backs. I'd recommend a high level of testing with any approach.
    – jammykam
    Commented Feb 20, 2017 at 10:32

1 Answer 1

1

Add the UserControlRenderer and GetUserControlRenderer classes to your solution, and patch the mvc.getRenderer pipeline with mvc.usercontrolrenderer.config and you’re good to go.

The source can be found at https://github.com/efocus-nl/sitecore-mvc-usercontrolrenderer

Detail: http://www.chrisvandesteeg.nl/2014/02/11/usercontrol-renderings-in-a-sitecore-mvc-website-wffm-for-mvc/

1
  • This works perfectly except for one change that has to be made. In WrapMvcRendering, on the line Field layoutField = args.ContextItem.Fields[FieldIDs.LayoutField]; you need to change it to Field layoutField = args.ContextItem.Fields[FieldIDs.FinalLayoutField]; to get all of the renderings in play. Commented Feb 22, 2017 at 1:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.