Хорошо, извините, попробуйте это:
<script language='javascript'>
var img = ['~/Content/img/sl1.jpg', '~/Content/img/sl2.jpg', '~/Content/img/sl3.jpg'];
function viewImage(id, next) {
let imgElement = document.getElementById(id);
let index = imgElement.getAttribute('index');
if (typeof index === 'undefined') {
index = 0;
}
if(next === 'next') {
index++;
if (index == img.length) index = 0;
}
else{
index--;
if (index < 0) index = img.length - 1;
}
imgElement.setAttribute('index', index);
imgElement.src = img[index];
}
</script>
<div>
<button onclick="viewImage('image','previous')">PREVIOUS
</button>
<button onclick="viewImage('image','next')">NEXT
</button>
</div>
<div>
<img id="image" src=""/>
</div>