현재 이미지, 다음 이미지 및 이전 이미지를 반환하는 Model 클래스가 있습니다.
슬라이드 전환을위한 액션이있는 컨트롤러가 있습니다.
이전 슬라이드와 다음 슬라이드 버튼이있는 Ajax.BeginForm에 의해 액션이 트리거됩니다.
페이지 새로 고치기없이보기 변경 슬라이드를 만들기 위해 수행 할 수있는 작업은 무엇입니까?
가 컨트롤러 :ASP MVC 4 페이지에서 이미지를 바꾸는 방법
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?')");
}
}
보기 : 클라이언트 측에
@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" />
}
jQuery.ajax 액션 호출을 사용하면 액션이 json을 반환합니다 (이미지 경로를 반환합니까? 또는 실제 이미지?) 및 반환 된 데이터가있는 jQuery를 사용하여 이미지의 src를 전환합니다 –
@Royi Mindel, 실제 이미지를 반환하는 작업. 하지만 나는 이미지를 저장할 수 있다고 생각합니다 ... 시나리오에서 json은 무엇입니까? 나는 컨트롤러의 동작에서 무엇을 반환하고 어떻게 사용하는지에 관해서는 다소 혼란 스럽다. – kroiz
http://tackoverflow.com/questions/4240619/how-can-i-replace-image-inside-a-td-with-loading-image-during-ajax-call 이것은 아약스 부분을 보여 주며, 당신은 당신의 행동을 사용합니다. 거기에 URL로, 그리고 이미지의 경로를 반환 –