c# - Asp.net web api routing issue? -


I am using Web API in my MVC application. I have a problem when calling the Web API using the Jquey.get function. Consider the following scenario:

I have 2 controller names:

  1. Home MVC controller <
  2. Li> / li>

    TestApi controller has 1 operation

    1. Received

      When I am indicating the homemcc controller The view was on >

        http: // localhost: 1025 / home   

      and when I call $ Get the expected Jason response from the Get ("api / testAPI / get") browser.

      But when I call homemcc controller ie

        http: // localhost: 1025 / Home / About   

      I $ Get the error from the browser ("api / testapi / get") , the resource is not found, and to find out what the resource is trying to do:

        Http: // localhost: 1025 / home / about / api / testAPI / get   

      instead of

        http: // localhost: 1025 / Why the  About Home /  was added to the API in the AP I / TestAPI / get   

      URL and why it was not added Home / Index See when I was on the index view index see why API calls up Damage is working and why About look ??

      You used to use a full URL.

      You should use a full URL instead:

        $ ("@ Url.RouteUrl" ("@ Url.RouteUrl" ("@ Url.RouteUrl" ("DefaultApi", New {httproute = "", Controller = "TestAPI", Action = "go"}))  < / Pre> 

      If you want to keep your javascript in separate JS files (and not in razor files) then what you can do is an initial method called Razor View.

      .js file:

        var myPageJsUrls = {}; var MyPageInitialize = function (getItemsUrl, saveItemUrl, editItemUrl) {myPageJsUrls.getItemsUrl = getItemsUrl; myPageJsUrls.saveItemUrl = saveItemUrl; myPageJsUrls.editItemUrl = editItemUrl; } Var getItems = function () {return $ .get (myPageUrls.getItemsUrl);} ...   

      razor In the file:

        & lt; scripts & gt; myPageInitialize ('@Lights "," items "),' @ Url.RouteUrl (" DefaultApi ", new { Httproute = "", Controller = "TestAPI"}, ...)     

Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -