Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

View doesn't refresh after RedirectToAction is done

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.

like image 203
Vengrovskyi Avatar asked Aug 14 '12 14:08

Vengrovskyi


1 Answers

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.

like image 79
HaBo Avatar answered Oct 23 '22 23:10

HaBo