Reputation: 111
We'd like to use the ASP.Net MVC Framework to extend (and gradually convert) an existing ASP.Net Webforms application which we've "inherited". I know that we can add MVC into a Webforms project, but the existing project is written in VB.Net and we would much prefer to use C# going forward.
Our ideal solution is to be able to add Controllers written using C# and Views also using C#, but I'm not sure that's possible.
Does anyone have any ideas how we could achieve this hybrid of languages as well as frameworks?
Upvotes: 2
Views: 235
Reputation: 111
Well it appears that we can achieve what we want to do. Just to see what happened, we tried changing the language declaration at the top of one of the Views in a test MVC application from "VB" to "C#" and (after closing and re-opening the file in Visual Studio) it seems to "just work". So we can write our views using C# syntax even though the web application is a VB.Net project.
Then by adding a reference 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 write all our MVC Controllers in C# too.
I've not actually tried doing this in our real legacy web application yet, but I'm hoping it will give us the ability to gradually migrate parts of the application to a C#/MVC solution.
Hope no-one minds me answering my own question!
Upvotes: 1
Reputation: 105029
That's quite easily possible but almost everyone would probably try to convince you not to do it because sooner or later you'll end up in a messier place that you'll hard get out of...
This one will be tougher. In case you have a Asp.net web site Project set up it's practically possible to make any kind of language combination. But combining this with MVC I don't think that would be a very wise idea.
But in case you have a Web Application Project so far (see the comparison) I don't think you'll be able to combine C# with VB.Net in a maintainable way (or maybe not in any way). At least you won't be able to put C# code inside Controller folder within your web project because you can't mix language in a single assembly.
Tough luck huh?
Upvotes: 1