I'm using Url.Action to generate the request link in an AJAX call. Then I manually append the Id to it.

$('#form #field').keypress(function (e) {
    if (e.keyCode == 13 || e.which == 13) {
        var val = this.value;
        var url = '@(Url.Action("action", "control"))' + '/' + val;
        $("#form").load(url);
    }
});

The problem is that each Url.Action seems to keep the last query strings. So if I call the function with the value 1, the second time that I call it url is:

var url = '/control/action/1' + '/' + val;

What's the right way to call Url.Action in JavaScript code?

Related posts

Recent Viewed