Is it possible to have a ASP.NET MVC MasterPage that has webforms User Controls which cause PostBacks?
I'm pretty sure the answer is going to be no here, but I just want to be sure. As you can probably guess I'm in progress of converting a web forms project over to ASP.NET MVC. Thus, I have a web forms master page and a MVC master page. The user controls (.ascx) render fine in the MVC Master page, but the post-backs essentially do nothing.
The best solution I know of is to开发者_开发技巧 have partials instead of user controls for the MVC master page. And then have an abstract controller that any controller that uses the MVC master page inherits from. Not exactly DRY, but it's the only thing I know of at this point. Any better ideas?
Thanks! Darren
Controls to postback such as submit buttons would work fine; anything that renders __doPostBack would not work, such as <button>, <a> (or LinkButton), <input type="button" />, etc.
Also, not sure of all the context, but consider the Html.Action MVC 2 syntax (if using MVC 2) as a way to achieve it too, which may be better depending on what's going on within the control.
You're correct - postback from a user control just won't work in a Mvc environment.
What I have done in a similar project is to gradually migrate the UserControls over to Partials called from MVC or from within webforms. [shameless plug] I have written about how to call RenderPartial and RenderAction here: http://www.blog.clicktricity.com [/shameless plug]
精彩评论