I am using Sitecore 8.2 with MVC.
I am trying to perform a page redirect, but my code isn't working.
I'm calling an MVC controller action method from JavaScript using a jQuery AJAX call.
The method is hit and the related items are also present in the content tree. But nothing happens. The current page remains and no redirection occurs. Also, there are no errors or messages in the browser console.
Controller method:
public ActionResult RedirectPage(string currentItemGuid)
{
Item pageItem = Sitecore.Context.Database.GetItem(currentItemGuid);
if (pageItem != null)
{
string pageURL = Sitecore.Links.LinkManager.GetItemUrl(pageItem);
//pageURL = /products/radio
string newURL = pageURL + "-type";
//newURL = /products/radio-type. This item is present in the content tree in the same folder structure.
return Redirect("~" + newURL);
}
else
{
return new EmptyResult();
}
}
JavaScript:
$(function () {
$(".ddlProducts").change(function () {
$.ajax({
url: "api/sitecore/Products/RedirectPage",
type: "POST",
data: { currentItemGuid: '{100-100-100}'},
context: this,
success: function (data) {
console.log("success", data);
},
error: function (data) {
console.log("error", data);
}
});
});
});
else
branch. Probably, the item is not found. – Dmytro Shevchenko Dec 16 '16 at 8:05return Redirect
with new url. – Qwerty Dec 16 '16 at 8:08