I have a Model class which knows to return current image, next image and previous image.
I have a Controller with an Action for switching slides.
That Action is triggered by Ajax.BeginForm which have a buttons for previous slide and next slide.
What can I do in the Action to make the view change slide without a page refresh?
Here is what I came up with so far:
Controller:
public class SlideshowController : Controller
{
static SlideshowModel slideshowModel = new SlideshowModel();
//
// GET: /Slideshow/
public ActionResult Index()
{
return View(slideshowModel);
}
public ActionResult GetCurrentSlideImage()
{
var image = slideshowModel.CurrentSlideImage;
return File(image, "image/jpg");
}
[HttpPost]
public ActionResult SlideshowAction(SlideshowModel model, string buttonType)
{
if (buttonType == ">")
{
slideshowModel.IncrementSlideNumber();
}
if (buttonType == "<")
{
slideshowModel.DecrementSlideNumber();
}
return JavaScript("alert('what to return to update the image?')");
}
}
View:
@model PresentationWebServer.Models.SlideshowModel
@using (Ajax.BeginForm("SlideshowAction", new AjaxOptions { UpdateTargetId = "result" }))
{
<img src="@Url.Action("GetCurrentSlideImage") " id="result"/>
<br />
<input class="float-left" type="submit" value="<" name="buttonType" id="btn-prev" />
<input class="float-left" type="submit" value=">" name="buttonType" id="btn-next" />
}