View doesn't refresh after RedirectToAction is done

Viewed 12385

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.

2 Answers

If you're using Ajax, return a script results to execute the navigation

instead of

return  RedirectToAction("DisplayCandidate",new {id=newCandidateId});  

try

 var viewName = "/Path/ViewName";
 var id = 1;
 var urlNavigate = string.Format("location.href='{0}?id={1}'", viewName, id);
 return new JavaScriptResult() { Script = urlNavigate };
Related