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.

Share:
12,024

Related videos on Youtube

Vengrovskyi
Author by

Vengrovskyi

Updated on September 15, 2022

Comments

  • Vengrovskyi
    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
      D'Arcy Rittich over 11 years
      Are you posting via AJAX? Show your client-side code.
  • HaBo
    HaBo over 11 years
    change your controller AddData method to get.
  • Saito
    Saito almost 9 years
    replace windows.location(retURL) with location.replace(retURL) also never use manual url contructing, us Url.Action("DisplayCandidate", new { id = newCandidateId })