开发者

Handle ASP.NET Web Form postbacks in MVC 3

开发者 https://www.devze.com 2023-03-31 06:05 出处:网络
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 do

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("~/"开发者_JAVA技巧 + 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?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号