Exchange of opinions, logic, etc. Between MVC Applications

We have an existing, fully functional ASP.NET MVC 2 application. I am creating an MVC 3 application that should have the same appearance as the existing one. That is, it must use the same navigational ascx, ascx header and footer, etc. The existing ascx application fills itself based on what is in the model, so this is not β€œjust” the user interface material that I want to use, it is the models and controller logic related to these controls.

Is there any good way to do this without significantly refactoring the original application? I heard about portable areas (http://lostechies.com/erichexter/2009/11/01/asp-net-mvc-portable-areas-via-mvccontrib/), but it seems that this will require significant refactoring on an existing application . I also looked at the Razor Single File Generator extension, which would allow us to compile the views into DLLs and share them, but this would require converting the existing application to MVC 3 and then to Razor views. (And I'm still not sure that after this it will be necessarily "easy.")

I don't notice anything obvious here? It just feels like there should be a good way to do this, but maybe the existing application just needs a major overhaul .: P

Thanks in advance!

+6
source share
2 answers

The simplest solution is probably to update MVC3 (trivial if you do not integrate with something that .NET 4 cannot use) and convert the views to Razor when moving the views to a shared library. The Razor view engine internally has several differences from the web form view engine, which make it easy to adapt for use in shared libraries.

In my own projects, I have a pre-compiled view engine that processes all the views, but it's easy enough to set up several view engines to use the first one to find a valid view. For layouts, you need to save the version for both view engines, but this is not a lot of extra effort if you have problems converting all views to Razor at the same time.

The general logic of the controller is quite simple. Define a controller in your shared library and subclass it in the controllers folder where the system will look for controllers.

+1
source

You can also explore this handy tool that converts MVC2 projects to MVC3 projects. I used it and it worked very well with minor adjustments after the conversion.

http://blogs.msdn.com/b/marcinon/archive/2011/01/13/mvc-3-project-upgrade-tool.aspx

+1
source

Source: https://habr.com/ru/post/890450/


All Articles