c# - No type was found that matches the controller named in asp.net website project -


i'm facing below error while ruing asp.net website project.

error: no type found matches controller named 'xxxx'.

route config:

 void application_start(object sender, eventargs e) {     // code runs on application startup    // authconfig.registeropenauth();     routeconfig.registerroutes(routetable.routes);      system.web.http.globalconfiguration.configuration.routes.maphttproute(            name: "defaultapi",            routetemplate: "api/{controller}/{action}/{id}",            defaults: new { id = system.web.http.routeparameter.optional }); } 

webapi controller:

  public class samplewebcontroller : apicontroller {     public object sampleaction(dictionary<string, string> jsonresult)     {      }  } 

url: serviceurl="../api/sampleweb"

please 1 provide idea on come error.

also let me know if i'm doing think wrong here.

thanks in advance.

if have multiple post actions in same controller should make route config this:

system.web.http.globalconfiguration.configuration.routes.maphttproute(            name: "defaultapi",            routetemplate: "{controller}/{action}/{id}",            defaults: new { id = system.web.http.routeparameter.optional }); 

then in controller can have multiple , post methods

  public class testcontroller : apicontroller   {          [actionname("postme")]          public object postme()          {          }           [actionname("postmetwo")]          public object postmetwo()          {           }          [httpget]         public object testget()         {          }   } 

then can generate post request action either using ajax or postman this:

localhost:xxxx/test/postme 

where test name of controller , postme name of action - both required

localhost:xxxx/test/postmetwo[post] localhost:xxxx/test/testget [get] 

Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -