Problem is I can’t name the web api controllers the same as my existing controllers.
You could have your API controllers with the same name as your existing controllers. Just put them in a different namespace to make the compiler happy.
Example:
namespace MyAppName.Controllers
{
public class ProductsController: Controller
{
public ActionResult Index()
{
var products = productsRepository.GetProducts();
return View(products);
}
}
}
and the API controller:
namespace MyAppName.Controllers.Api
{
public class ProductsController: ApiController
{
public IEnumerable<Product> Get()
{
return productsRepository.GetProducts();
}
}
}
and then you have: /products and /api/products respectively to work with.