Reputation: 11
trying to add/change the values of the parameters in the url, but can't able to change/add the values
trying to add/change the values of the parameters as shown below var Filename ='abc.pdf'; var strUser='john'; var url = '@Url.Action("Action","Controller", new{ filename="name", username="User" })'; window.location.href = url.replace('name',Filename + 'User', strUser);
but not able to do it
Upvotes: 0
Views: 105
Reputation: 577
Try This:
var downloadUrl = '@Url.Action("Download", "File", new { filename = "default.pdf", username = "default" })';
var Filename = 'abc.pdf';
var strUser = 'john';
var url = downloadUrl.replace('default.pdf', Filename).replace('default', strUser);
window.location.href = url;
Upvotes: 0
Reputation: 34
try this
var url = new URL('http://demourl.com/path?id=100&topic=main');
var search_params = url.searchParams;
// new value of "id" is set to "101"
search_params.set('id', '101');
// change the search property of the main url
url.search = search_params.toString();
// the new url string
var new_url = url.toString();
// output : http://demourl.com/path?id=101&topic=main
console.log(new_url);
Upvotes: 2