I'm trying to display list items with AJAX. First, when you go into the page, you will see the first item of the list. After clicking "Next", then AJAX will refresh its div with the next item in the list.
Controller
public ActionResult Index()
{
if (Request.IsAjaxRequest())
{
return PartialView(_attractionList.ElementAt(1)); // next element in the list
}
return View(_attractionList.First());
}
View
@model EasyTripNow.Models.Attraction
@{
ViewBag.Title = "Index";
}
@Html.Partial("_Attraction", Model)
@using (Ajax.BeginForm(
new AjaxOptions()
{
HttpMethod = "get",
InsertionMode = InsertionMode.Replace,
UpdateTargetId = "newAttraction"
}))
{
<input type="submit" value="Next"/>
}
Attraction Partial view:
<div id="newAttraction">
<h4>Attraction</h4>
@Html.EditorForModel(Model)
<p>
@Html.ActionLink("Edit", "Edit", new {id = Model.ID}) |
@Html.ActionLink("Back to List", "Index")
</p>
</div>
Can't think of a good way to do it.
Any suggestions?
Aucun commentaire:
Enregistrer un commentaire