0

I want to write a collection of Single Page Apps in .NET using MVC and Angular JS (1.x). I would like to manage the bootstrap of each SPA using MVC all within a single project so that the look and feel is consistent using the _Layout and Return view(); But I would like the data binding in the ng $scope to get and post via api calls. How do you mix MVC controllers and API controllers in the same project when they could logically have the same name. E.g. The MVC controller to bootstrap the Product SPA would be ProductController : Controller and the data calls would be in an API controller ProductController : apiController

The routes to these would be different: baseURL/products/... for the MVC and baseURL/api/products/... for the API calls. How does the router know which controller to call as they do not technically have to live inside the Controllers folder. Prefixing the API Controllers with api seems a bit of a cludge and creates ugly URLS - granted they should only ever be consumed by the javascript but if I want to make them available externally I would prefer them to be clean.

11
  • Use a different namespace? Commented Jun 9, 2015 at 19:50
  • Isn't this all set up for you when you create a new Web Application and choose MVC and then select Add folders for Web API? Commented Jun 9, 2015 at 19:51
  • @Obversity. Thanks for the speeds response; I am still getting to grips with .NET and namespace is not something I have really investigated yet. How does the namespace relate to the routing and how would it determine which controller should be used. How would you recommend setting up the namespaces mvc.product.app and api.product.app or should the mvc/api bit go at the end? from a tortological perspective they should be in the same namespace as they both form part of the same process. Commented Jun 9, 2015 at 19:55
  • you can configure your controllers through RouteConfig and WebAPIConfig files.It will diffrerentiate your MVC Controller and WebAPI Controller in a project Commented Jun 9, 2015 at 19:57
  • @Yuri. Idon't think so, you still only get one Controllers folder and when you create a Controller class file you have to decide whether to use MVC or API scaffolding so you still end up with two files with the same name and two classes with the same name unless you can find a way to differentiate them. Commented Jun 9, 2015 at 19:57

1 Answer 1

0

Have a look at here. I think it would be better to use a separate project for WebAPI and MVC.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.