0

I have a page with Search bar. Once the user hit the GO button the user should be taken to the Search\Index view where the result will be shown.

The button click event correctly sends the request to the Index action in Search controller.

The model is also populated.

After clicking the button, I see the page populated in the Response in FireBug.

Why the page remains on the previous page?

I want the browser to change the URL by doing a refresh.

This action is called via ajax Get Request

[HttpGet]
public ActionResult Index(string keys)
{
  //get data from db
  //populate model with data from db
  return View(model);
}

Am I missing something? I tried to do a RedirectToAction but that fails as that a redirect to itself.

kheya
  • 7,546
  • 20
  • 77
  • 109
  • Have you tried it without Ajax? Is there a reason to use Ajax? Redirect using Ajax can become unnecessarily complicated. You can see the details in this answer http://stackoverflow.com/questions/19762629/calling-response-redirect-through-ajax – Yogiraj May 28 '14 at 02:00
  • If you want the browser to change the URL by doing a refresh why are u using Ajax? Use default behaviour of sending model to controller on form sumbit and redirect to respective view. – Nitin Varpe May 28 '14 at 05:57
  • can you post your ajax request.. – Romeo May 28 '14 at 09:01
  • I am pretty sure you can not do a server side redirect using Ajax. Your options are either do a standard request which will preform the page request OR write some JQuery in the OnSuccess() of the ajax options to preform the page refresh (redirect) for you. I think you just need to do a standard html.BeginForm call to achieve all you want and you should ignore ajax. – KevDevMan May 28 '14 at 12:08
  • You cannot redirect from an ajax post. – Travis J May 28 '14 at 16:58
  • Use an actual request and not an ajax call. – Travis J May 28 '14 at 16:59

0 Answers0