Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am trying to modernize an existing web application that was built using ASP.NET Web Forms. I'm trying to that by wrapping it inside MVC 3 (Razor) and using the views from there. What I have been doing so far is to use Server.Execute method in order to get HTML content that I can return as HTML and render inside the View in MVC 3. It executes an .aspx file like this:

var writer = new StringWriter();
ctx.Server.Execute("~/" + aspxPath, writer, true);
string html = writer.ToString();

In order to route everything via MVC 3 I had to set the RouteExistingFiles property to true:

RouteTable.Routes.RouteExistingFiles = true;

This is all good until I must handle postbacks from forms. Postbacks work if I don't set the RouteExistingFiles property, but then only the body content part is shown since it bypasses the MVC 3 routing. As you can see above I tried to set "preserveForm" to true when calling the Execute method, but to no help. Is there any way to handle postbacks in MVC 3 that originates from a regular form in ASP.NET Web Forms? And is there any other way (totally different maybe) to try and solve my problem when I want to reuse many .aspx files and present them another way in MVC 3?

share|improve this question
    
Seeing as you aren't converting the templates to MVC or leveraging MVC in your port, why not just leave the forms based pages side-by-side with any new MVC razor code. If you decide to convert them, port them properly. –  TheCodeKing Aug 29 '11 at 12:56
    
For anyone interested, I ended up using common header, menu and footer .html-files and rendering them side by side with the content. This is done differently for .aspx pages and new Razor pages but yields the same layout, feel and look - and it works perfectly. –  perkrihe Dec 13 '11 at 9:36

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.