Can I use ASP MVC in ASP.Net WebForms applications (using 2 different programming languages!)

We would like to use the ASP.Net MVC Framework to extend (and gradually transform) an existing ASP.Net Webforms application that we "inherited". I know we can add MVC to a Webforms project, but the existing project is written in VB.Net and we would rather use C # in the future.

Our ideal solution is to add controllers written using C # and Views using C # too, but I'm not sure if this is possible.

Does anyone have any idea how we could achieve this hybrid of languages ​​as well as structure?

+2


source to share


2 answers


Well, it looks like we can achieve what we want. To see what happened, we tried to change the language declaration at the top of one of the views in the MVC test app from "VB" to "C #" and (after closing and reopening the file in Visual Studio) it looks like "just go". Therefore, we can write our views using C # syntax even if the web application is a VB.Net project.

Then by adding a link to a separate C # Controllers project and adding the following line to the Application_Start () method in global.asax;

        ControllerBuilder.Current.DefaultNamespaces.Add("Controllers")

      



We can also write all of our MVC controllers in C #.

I haven't tried this in our real web application yet, but I hope it gives us the ability to gradually migrate parts of the application into a C # / MVC solution.

I hope no one minds that I answer my own question!

+1


source


Combining web forms with MVC

This is quite easily possible , but almost everyone will probably try to convince you not to , because sooner or later you will find yourself in a dirty place from which you will get out ...

Combining C # with VB.net



This one will be tougher. In case you have the Asp.net Project website, it creates just about any combination of languages. But when combining this with MVC, I don't think that would be a very wise idea.
But if you have a web application project so far (see comparison ), I don't think you can combine C # with VB.Net in repair (or maybe not anyway). At least you won't be able to put C # code inside the Controller folder in your web project because you can't mix the language in the same assembly.

Tough luck huh?

+1


source







All Articles