0

I am calling an action method from a Ajax.ActionLink as follow:

@Ajax.ActionLink("By Biggest price"), "CatSearch",
    new { sortBy = "PriceBiggest" },
    new AjaxOptions() { HttpMethod = "GET", OnBegin = "$('#ajaxReplace').hide();", OnComplete = "$('#ajaxReplace').show();", LoadingElementId = "busyDiv", UpdateTargetId = "ajaxReplace" },
    new { @class = "btn btn-xs btn-warning boxShadow", @style = "margin-top: 5px;" })

This part works fine! Since my ProductController has an [Authorize] attribute well the user is redirected to the login page and its alright also. Post/After a success login I want to redirect to my Controller Action (same url as before login that was rendered by the ajax.actionlink)

The action returns a PartialView using but the problem is that when I redirect to the PartialView it doesn't inherit the _Layout page most probably because it wasn't called from the parent.

I am not sure how to approach. I am sure there's something very easy and simple. I tried few things like window.location/javascript.. If only I could simulate after the success login the same call as the ajax.actionlink! :(

Any ideas, help please?

Jasen
  • 14,030
  • 3
  • 51
  • 68
  • 1
    AJAX is usually used when you _don't_ want to navigate away from the page. Redirect result is not followed by AJAX so you must use client-side JavaScript to do the navigation yourself. – Jasen Jul 05 '16 at 19:00
  • From my AccountController Login action, what should I return exactly? a Javascript ActionResult? any examples? – Martin MightyMart Lauzon Jul 05 '16 at 19:23
  • Maybe a better question would be, Is it possible to return a Json action result without calling the action from a AjaxLink, Jquery, javascript or Ajax beginform? if yes, how to link the Json result to the view, ex would be appreciated? – Martin MightyMart Lauzon Jul 06 '16 at 12:24
  • i came across this example BUT the redirection should simulate an Ajax.Actionlink and the sample code will not call async/ajax way. CODE return Json(new { redirectUrl = Url.Action("Index", "Home",e), isRedirect = true }); success: function(json) { if (json.isRedirect) { window.location.href = json.redirectUrl; } } – Martin MightyMart Lauzon Jul 06 '16 at 12:30
  • There are several answers that may help you [here](http://stackoverflow.com/q/5258721/2030565), [here](http://stackoverflow.com/q/20888316/2030565), [here](http://stackoverflow.com/q/7975311/2030565), and [here](http://stackoverflow.com/q/199099/2030565). When you return a JSON result to AJAX you'd usually have the client-side script build a view or act on the data to perform some logic. Your last comment performs logic with the JSON response (and I don't see why it isn't asynchronous). – Jasen Jul 06 '16 at 18:00

0 Answers0