2

I have an existing MVC 3 web application that includes web pages only and have been developed with Visual Studio 2010.

Now, I have a new requirement to develop REST web services:

With MVC 4 and Visual Studio 2012, I think I would pick the "Web API" project template under ASP.NET MVC 4 Project dialog in VS 2012.

And with the "Web API" project template, I could merge the existing MVC 3 web application into that new "Web API" project to continue developing that existing MVC 3 project. AT THE SAME TIME, I am able to develop REST web services inside that "Web API" project, too.

Is my thought the right way to go? If so, how can I merge or convert the exsting MVC 3 web application into the MVC 4 "Web API" project so there is nothing to be broken?

1
  • very ambitious. I wish you luck! Jan 30, 2013 at 22:35

1 Answer 1

0

I would upgrade the MVC3 project to MVC4. You can add Web API controllers to an MVC4 project.

You will probably need to add a route for the API:

  routes.MapHttpRoute(
      name: "DefaultApi",
      routeTemplate: "api/{controller}/{id}",
      defaults: new { id = RouteParameter.Optional }
  );
2
  • Thank you, Steve. The reason why I want to make REST web service project and MVC web project in one project only (as "Web API" selected with VS 2012) is I am able to use the existing port in IIS that was already set up in production. Also, the same URL is used for both web pages and REST web services. Jan 31, 2013 at 13:23
  • @Thomas.Benz, I see what you mean. My solution wouldnt work. Unfortunately, no tool for this. Look at the link on Steve's answer. It's an involved process, but that is the correct way. The only other way (and I've done it) was to literally open a new mvc4 project and add every controller, model, and view using the add item menu in solution explorer. Jan 31, 2013 at 13:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.