Had to Roll Back Asp.Net MVC
Early on in the MVC Previews, the method RenderUserControl was provided. It was a perfect fit for the concept of rendering a "control" or a "partial" as it did all the work of executing the lifecycle of that control and then returned the html as string output. You could then use that html in any way you saw fit. You may have wanted to store that output in a database or add it to an object structure and then serialize that as JSON. Whatever! You were left to your own ingenuity and resourcefulness to accomplish your business objectives.
That method is GONE. There is no equivalent, that I can find, that will give you access to the html output as a string. It looks like the solution is going to be to replicate that behavior some other way and write all the code yourself. This is really, really unfortunate. See, there are a lot of cases where a control from web forms worked in Mvc except for some strangeness. There might be some view state or a bunch of extra markup that you don’t want or you may have wanted to modify or clean up the html before adding it to your page. Furthermore, there may be an expected render error that you aren’t able to prevent because the control is compiled and you don’t have the source code. Wrapping RenderUserControl in a try catch gave you the ability to catch that problem and deal with it. Gone. Just gone.
Since we used RenderUserControl 61 times in our website, I was not prepared and do not have time to refactor and test all that code. My unit tests will no longer work because I cannot test the output of rendering a control, I can only embed that control in the mark up. The problems that I was handling before are now going to blow up my page. I suppose I can inherit from and extend the Controls in question but that is just big waste of time when all I want to do is handle the errors that the author didn’t.
So I’m rolling back to Preview 4 until I have about a week to dedicate to the update.
I suppose I should have known better than to use Preview Code on a production app but my alternative was either Castle or WebForms. Neither is as pleasing as Asp.Net MVC.
October 23rd, 2008 at 12:32 pm
Can’t you use RenderPartial instead?
November 11th, 2008 at 11:00 am
I cannot use RenderPartial because we were using RenderUserControl in two conditions that RenderParial does not support. 1) to catch exceptions thrown by 3rd party controls where we had a fall back result. 2) to modify the resutling html in some way after the control has produced output that is not completely satisfactory. I am looking more closely, now, at method available on the Controller. I’ll follow up when I have an answer (or not)