Reputation: 31
I have been trying in JavaScript to reload a page to particular controller's action method with a parameter but getting error.
My output works when I use
function fnReload(){
window.location.reload(true);
}
But I want to redirect to controller's action method with PARAM's value and I am trying this
function fnReload(){
// Gives me the value in a function
var supId = data.supplierId;
//redirects the page so the I can see the updated the data
window.location.reload= '@Url.Action("GetSupplier", "Supplier", new { supplierId = supId })';
}
But it is also not working for me since it give me the error and on applying breakpoint on server side it doesn't go over there.
Can some one guide me what should I do reload the page and redirect to controller's action method.
Thanks in advance.
Upvotes: 0
Views: 1485
Reputation: 26
You can use AJAX call for this
// AJAX call
$.ajax({
url: "GetSupplier",
type: "get",
data: {
supplierId: supId,
},
success: function(result) {
result = JSON.parse(JSON.stringify(result));
console.log(result);
window.location = "/GetSupplier";
},
error: function(result) {
result = JSON.parse(JSON.stringify(result));
console.log(result);
}
});
Upvotes: 0