简体   繁体   中英

Odd Behavior with Ajax call to MVC Controller Method

I am experiencing some odd behavior with MVC, Ajax and saved credentials. Although I have a work around, I was wondering if someone could help me understand what the issue might be.

I am using the DataTables jQuery plug-in to display the results of a call to my Controller's action method. Here is a sample of that call:

$('#grdTournamentList').on('init.dt', function () {
     $("input[name='TournamentSelect']").on("change", function () {
            $('#btnMoveNextStep1').removeAttr("disabled");
            });
     }).DataTable({
            "ajax": {
                 "type": "POST",
                 "contentType": "application/json; charset=utf-8",
                 "url": "QuickStart/TopTenMostRelevantTournaments",
                 "data": {},
                 "dataType": "json",
                 "dataSrc": ""
                }
      });
});

If I use the code as is during the user's first login (allowing the credentials to be saved locally), the TopTenMostRelevantTournaments method call is made successfully and the grid is populated.

Request: /XXXX/XXXXX/ /TopTenMostRelevantTournaments / TopTenMostRelevantTournaments

If the user closes the browser and attempts to go back in, the saved credentials will bypass the login and take the user to the view containing the grid. At this point the call to the controller fails. While debugging it, I see that the generated URL for the ajax call is incorrect. The Controller appears twice:

Request: /XXXX/XXXXX/ TopTenMostRelevantTournaments TopTenMostRelevantTournaments

If I change the ajax call to use the Razor @URL.Action method when setting the URL. The call works without an issue.

"url": "@Url.Action("TopTenMostRelevantTournaments", "QuickStart")",

My question is why is this happening? Why would saving the user's credentials cause this odd behavior? Please note that the rest of the application works fine.

Thanks in advance!

查看评论中的答案

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM