diff --git a/src/Umbraco.Web/Editors/ContentController.cs b/src/Umbraco.Web/Editors/ContentController.cs
index d003636aac..1a5a68f3f7 100644
--- a/src/Umbraco.Web/Editors/ContentController.cs
+++ b/src/Umbraco.Web/Editors/ContentController.cs
@@ -467,7 +467,7 @@ namespace Umbraco.Web.Editors
}
///
- /// Change the sort order for media
+ /// Change the sort order for content
///
///
///
@@ -485,23 +485,33 @@ namespace Umbraco.Web.Editors
return Request.CreateResponse(HttpStatusCode.OK);
}
- var contentService = Services.ContentService;
- var sortedContent = new List();
try
{
- sortedContent.AddRange(Services.ContentService.GetByIds(sorted.IdSortOrder));
+ var contentService = Services.ContentService;
+
+ // content service GetByIds does *not* order the content items
+ // so we need get them in the proper order here - no need to sort!
+ var content = contentService
+ .GetByIds(sorted.IdSortOrder)
+ .ToDictionary(x => x.Id, x => x);
+
+ var sortedContent = sorted.IdSortOrder.Select(x =>
+ {
+ IContent c;
+ return content.TryGetValue(x, out c) ? c : null;
+ }).WhereNotNull();
// Save content with new sort order and update content xml in db accordingly
if (contentService.Sort(sortedContent) == false)
{
- LogHelper.Warn("Content sorting failed, this was probably caused by an event being cancelled");
+ LogHelper.Warn("Content sorting failed, this was probably caused by an event being cancelled");
return Request.CreateValidationErrorResponse("Content sorting failed, this was probably caused by an event being cancelled");
}
return Request.CreateResponse(HttpStatusCode.OK);
}
catch (Exception ex)
{
- LogHelper.Error("Could not update content sort order", ex);
+ LogHelper.Error("Could not update content sort order", ex);
throw;
}
}