0

I have a problem how to reuse the webforms masterpage in mvc view. The project I am working on is an existing website where I have to change a single module to MVC. I have implemented successfully the routing logic but I am struggling with reusability of masterpages. I read this question here but it does not solve my problem because existing pages inherit from XClass which by itself inherits from System.Web.UI.Page. The same logic happens to be for mastepages. The reason is because the XClass makes a lot of logic in background - like dealing with session values and validating user data etc etc. Is there any way how can I use those masterpages within view in MVC? I tried the solution given in question above but while debugging there is a statement XClass xpage = Page as XClass in Page_Load event which gives me the value null and throws exception since in MVC we do not have Page_Load event etc... As I have read in other places they recommend to create a new masterpage for MVC but in my condition it would be very difficult. Any suggestion how to solve this problem ?

I am reading this article here but yet I am not clear how to implement it...

Here I have an image attached for masterpage in webforms.

enter image description here

Community
  • 1
  • 1
Rey
  • 3,663
  • 3
  • 32
  • 55
  • What view engine are you using in MVC? Why did you tag this as MVC 3? – mason Jan 26 '17 at 20:43
  • I am not using Razor because as far as I know the only way to use aspx masterpages in the views is to use aspx syntax. I tagged mvc 3 because I think this problem has to do with mvc 4 and 3 in general... – Rey Jan 26 '17 at 20:51
  • If you are not using MVC 3 in your project, don't tag it in your question. – mason Jan 26 '17 at 20:53
  • Ok thanks, I will consider that in other questions, but I thought it would relate to others for the same too. – Rey Jan 26 '17 at 21:04
  • Even if you manage to get this running, none of the Web Forms controls will work in MVC. Those are for Web Forms. You're really going down the wrong route here. If you're going to move to Web Forms, then rewrite the functionality to follow proper MVC practices, including using a modern version of MVC and a well supported view engine. – mason Jan 26 '17 at 21:06
  • Well the masterpages has only links to redirect me to other places. For example there is navigation bar and right side bar, nothing else. But thanks for the answer. If you recommend to do so, I will think to add another project based in MVC. – Rey Jan 26 '17 at 21:25
  • You can do it in the same project. You don't have to do a different project. MVC 5 can run alongside Web Forms just fine. Just maintain your links in an MVC layout page as as well as the master page. Once you've got all functionality converted over to MVC from Web Forms you can remove the Web Forms stuff. – mason Jan 26 '17 at 21:27
  • Ok I will try to do so, thanks for your time. – Rey Jan 26 '17 at 21:31
  • The master pages is reusable in any MVC version if there are no server controls (excluding `asp:ContentPlaceHolder` & `asp:Content`) being used, especially any controls rely on `ViewState`. All HTML tags and helpers can be reused too, just remove `runat="server"` attribute on them if exists. – Tetsuya Yamamoto Jan 27 '17 at 00:37

0 Answers0