View doesn't refresh after RedirectToAction is done
12,024
Because you are using Ajax Post
public ActionResult AddData(CandidateViewModel viewModel)
{
var newCandidateId = 0;
newCandidateId = this._serviceClient.AddCandidate(viewModel);
string ReturnURL = "/DisplayCandidate/"+newCandidateId;
return JSON(ReturnURL);
}
and in your Ajax Post Method:
Onsuccess(function(retURL){ window.location(retURL); })
This will take to the new Action and that Action will return View.
Related videos on Youtube
Author by
Vengrovskyi
Updated on September 15, 2022Comments
-
Vengrovskyi over 1 year
Here is my problem:
[HttpPost] public ActionResult AddData(CandidateViewModel viewModel) { var newCandidateId = 0; newCandidateId = this._serviceClient.AddCandidate(viewModel); return RedirectToAction("DisplayCandidate",new {id=newCandidateId}); } public ActionResult DisplayCandidate(int id) { var candidateViewModel= this._serviceClient.GetCandidate(id); return View(candidateViewModel); }
After filling the form viwemodel sends to server. After data were stored, flow is redirected to DisplayCandidate action and it goes there but page didn't refresh. I don't understand why! Help, please.
-
D'Arcy Rittich over 11 yearsAre you posting via AJAX? Show your client-side code.
-
-
HaBo over 11 yearschange your controller AddData method to get.
-
Saito almost 9 yearsreplace
windows.location(retURL)
withlocation.replace(retURL)
also never use manual url contructing, usUrl.Action("DisplayCandidate", new { id = newCandidateId })