I have completed an ASP.NET-MVC5 application(website) where I have lot of MVC controllers:
I would like to extent the functionality of my application by exposing WEB API with OData.
For instance I would like to create another controller for Person
model class, but this time it should be Web API not MVC controller. Should I WEB API store it in Controller folder and just call it PersonWebAPIController
? Will it work?
To answer your question Will it work?
yes
But if you want to separate code physically, then you can create a custom folder under Controllers
folder, and place all the ApiControllers
in newly created folder. If you want to separate MVC and API controllers logically, then use different namespaces
for them.
Technically you can have controllers in any custom made folder under the Visual studio project.
You can remove the default routing and use attribute based routing to achieve this. Add all your ApiControllers to an "API" folder with a [Route] attribute with correct routing.
Please have a look at this link for more details.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With