How do I maintain scroll position in MVC?

I’ve resolved this in JS :

$(document).scroll(function () {
  localStorage['page'] = document.URL;
  localStorage['scrollTop'] = $(document).scrollTop();
});

Then in document ready :

$(document).ready(function () {
  if (localStorage['page'] == document.URL) {
    $(document).scrollTop(localStorage['scrollTop']);
  }
});

Leave a Comment