2

I'd like to keep my code compact and concise, so I'd like to emulate the MVC 6 Controller class instead of maintaining a separate Controller and ApiController. This post gets pretty close, but I'd like to remove the JSON assumption and support content negotiation. (Admittedly, I'll most likely use it only for the JSON functionality, but I like being flexible.)

Can anyone provide a simple example of an MVC 5 Controller with a method supporting content negotiation that could be called from AJAX? Optionally, an explanation of the sample would also be appreciated.

Community
  • 1
  • 1
ricksmt
  • 888
  • 2
  • 13
  • 34
  • I've used Restfulie to do ConnNeg in MVC since MVC 3 or 4. https://github.com/mauricioaniche/restfulie.net otherwise you can just roll your own ActionFilter to do it – Chris Marisic Dec 08 '15 at 23:26
  • We ended up using AngularJS which took the MVC controller logic client side. Everything else was refactored into a separate Web API project. – ricksmt Feb 05 '16 at 23:49
  • I like to try to keep my stack unified as much as possible. Unless it's inherently different like SignalR since there's no way to do that with anything MVC provides – Chris Marisic Feb 08 '16 at 15:28

0 Answers0