asp.net mvc - Jquery ajax url in controller action -


can body explain how jquery ajax method url points controller action?i mean machinery behind technology.for example

 $("#location").autocomplete({         source: function (request, response) {             $.ajax({                 url: '/vacancy/autocompletelocations',                 data: request,                 datatype: "json",                 type: "get",                 minlength: 2,                 success: function (data) {                     response($.map(data, function (item) {                         return { label: item.ref_desc, value: item.ref_desc, id: item.ref_id }                     }));                 }             });         },         select: function (event, ui) {             $("#hdlocationid").val(ui.item.id);         }     }); 

i want know how url: '/vacancy/autocompletelocations' points particular action means machinery.

an application has called route table. route table maps particular urls particular controllers. application has 1 , 1 route table. route table setup in file. in case don't have route table, application give 404 error.

public static void registerroutes(routecollection routes) {     routes.ignoreroute("{resource}.axd/{*pathinfo}");      routes.maproute(         "default", // route name         "{controller}/{action}/{id}", // url parameters         new          {               controller = "home",               action     = "index",               id         =  urlparameter.optional          } // parameter defaults     );  } 

case -1. consider case when have area in application. but, did not mention area name in url. example localhost/controllername/actionname. if pay attention url, there no area name. there no such controler in root controller directory. controller exists in area. let's have following area in application.

area

now type url : localhost/test/index , hit enter. question happening in background?

let's added reference of rouredebugger. can dll location. added line of code in file under application_start handler.

routedebug.routedebugger.rewriteroutesfortesting(routetable.routes); 

when execute application. shows me following output, instead of index page response.

routedebugging

if pay attention above screenshot, default route enabled present in file. it's because default url without constraint locate controller anywhere in application. view neither present in root folder view's directory nor present in shared folder view's directory. 404 error.

how can rid of issue ?

i faced similar issue in past , found corrective action. below new version of default route in file.

public static void registerroutes(routecollection routes) {     routes.ignoreroute("{resource}.axd/{*pathinfo}");      var route = routes.maproute(         "default", // route name         "{controller}/{action}/{id}", // url parameters         new          {              controller = "home",              action     = "index",              id         = urlparameter.optional          }, // parameter defaults         new[] { "mvcapplication1.controllers" }     );     route.datatokens["usenamespacefallback"] = false; } 

in above code added namespace in constraint , route.datatokens["usenamespacefallback"] = false; in route. after doing , using above mentioned url, controller action method never executed because area name not present in controller.

also figured out 1 more important information regarding datatokens when url not contains area name , default route not contain namespace information. below screenshot.

datatoken without namespace

the data token information not available when url not contains area name , default route not contain namespace information.




now, after adding namespace , adding area name in url per revised default route. datatoken information shown below in screen shot.

data token namespace




below routedata output after adding area name in url

route debugging

as can see area route enabled now.

hope you. thanks


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -