while this seems easy, it isn't working

Here is my code

 public ActionResult RenderSelectedItem(string id)
        var itemURL = Sitecore.Context.Database.GetItem(id);
        var link = Sitecore.Links.LinkManager.GetItemUrl(itemURL);
        return Redirect(link);

I am calling this action from this .ajax routine:

 $("#SearchBtn").click(function () {
        var textval = $("#SubCatagoryList :selected").text();
        var selected = $("#SubCatagoryList :selected").val();

            type: "GET",
            url: "api/Sitecore/MultiSelectAndSearch/RenderSelectedItem/",
            data: { id: selected },
            content: "html",
            success: function (response) {



I am hitting the Action and getting the ID, but the Redirect doesn't redirect to the item's link. upon further investigation ... it looks as though my Ajax call response is in error

2 Answers 2


You cannot redirect from an AJAX post. You could return the URL you want to redirect and redirect from Javascript.

success: function(response){
   window.location.href = response;
  • thank you, almost there... I did try something like this before but how am I formulating my "response" return ... I tried returning a JSON object and then I also tried returning the item path as a string, neither is working Aug 30, 2017 at 12:19

The response from Controller should be JsonResult, in which you can define the Url that you want to redirect.

new Json { newurl = link };

Then in the success method of ajax, you can do window.location.href = response.newurl for example.

  • This is what I would have done.
    – AlokBhatt
    Aug 31, 2017 at 5:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.