How to use ASP.Net MVC View inside WebForms .aspx page?

吃可爱长大的小学妹 提交于 2019-12-04 05:45:48
Ivan Zlatev

I saw this question and I remembered that I've read a few posts by Scott Hanselman regarding this, so here you go:

Also two more articles on the subject:

I think to summarize you can:

  • Have ASP.NET MVC and ASP.NET WebForms side-by-side, such as that you can have the new views in ASP.NET MVC and the old ones will remain in WebForms (if it works why rewrite it?). You "just" need to figure out how to share the master page.
  • You can use basic WebForms controls inside non-Razor ASP.NET MVC views, but if they use PostBacks or require ViewState - they won't work, because the full WebForms lifecycle isn't there in ASP.NET MVC views.
  • Regarding partial views inside WebForms. Uou can hack/force the ASP.NET MVC pipeline to render a route/view to a string and append that to your WebForms page. The problem and question however is how useful is that since you will loose the model binding during POST as well as MVC model validation if you are doing edits. Some code to render a view - How to include a partial view inside a webform . You can also always pull the partial view using ajax if need be.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!