Changing MVC Razor Img src with javascript
This is a MVC application. I have a IEnumberable(Of T) viewmodel that is
passed in to the partial view. There will be a next and prev. image button
on the lower part of the page. The Idea is simple. When the user clicks
the Next Button it shows the next image and when they click the prev.
button it shows the previous image. I have started working on the below
javascript to achieve this. However as I am totally new to javascript I
feel that I am missing something here.
<script type="text/javascript">
var c = 0;
function PreviousImage() {
c -= 1;
if (!c < 0) {
('@m')=c
document.getElementById("photoBox").src =
('@Url.Content(String.Format("~/PropertyImages/{0}/{1}",
Model(m).PropertyImageFolder, Model(m).PhotoName))')
}
}
the div container for the image and the buttons is as follows:
<div>
<img src="" id="photoBox" />
<input type="button" id="NextImage" value="Next Image" /><input
type="button" id="PrevImage" value="Previous Image"
onclick="PreviousImage()" />
</div>
m is just a vb local variable in the view that gets set when c is
incremented. So that I can get the model item by index.
Any suggestions? Am I on the right Track? Or is this a total fail of an
attempt at what I am after?
No comments:
Post a Comment