UPDATE: I unloaded the project and re-did it again and it worked.
I'm trying to create a WebApi, my build works fine and I get the error message "No type was found that matches the controller named" when I try to go to URI
This is how my webapiconfig looks like,
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
}
And below is my controller,
public class ClientController : ApiController
{
public List<Client> Get()
{
ICRepository repository = new CRepository(new CContext());
return repository.GetAllClients().ToList();
}
And this is how my global.asax.cs file looks like,
public class MvcApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
WebApiConfig.Register(GlobalConfiguration.Configuration);
GlobalConfiguration.Configure(WebApiConfig.Register);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
}
}
I'm trying to browse to the url "http://localhost:50662/api/client"
The complete error is as below,
This XML file does not appear to have any style information associated with it. The document tree is shown below. No HTTP resource was found that matches the request URI 'http://localhost:50662/api/Client'.No type was found that matches the controller named 'Client'.
My question is different from what it's been marked as duplicate of, the question uses just controller which is MVC and mine is "ApiController" and I did read that before creating this. Also, the marked answer there is similar to what I have in here and my problem still exists.
Any help would be highly appreciated. I'm really lost.