我试图在ajax调用后更新partialview,部分视图正在更新,但之前的内容未从屏幕上删除。 我现在在屏幕上显示了当前结果和当前结果。 那是我的代码:
public ActionResult FindMovies(string text)
{
ViewBag.ShowButton = Rented;
FindMovie(text);
if (movies.Count == 0)
ViewBag.Movies = "null";
else
ViewBag.Movies = "notNull";
return View(movies);
}
public ActionResult Rent(int id)
{
if (Rented.Equals("no"))
{
movieRent = db.Movies.Find(id);
movieRent.UserRent = userId;
movieRent.Rented = true;
db.Entry(movieRent).State = EntityState.Modified;
db.SaveChanges();
Rented = "yes";
movies.Find(x => x.ID == id).UserRent = userId;
movies.Find(x => x.ID == id).Rented = true;
}
return PartialView("MovieList", movies);
}
观点:
<div class="center">
@{Html.RenderPartial("MovieList", Model);}
</div>
及其部分观点:
@model IEnumerable<MvcMovies.Models.Movies>
<ul class="result">
@foreach (var item in Model)
{
<li>
<table>
<tr>
<th>
<figure>
<img src="@Url.Content(@item.Path)"
width="100" height="100" alt="movie logo" />
</figure>
</th>
<th>
<article>
<div class="editor-label">
@Html.DisplayFor(modelItem => item.Name)
</div>
<div class="editor-label">
@Html.DisplayFor(modelItem => item.Year)
</div>
<div class="editor-label">
@Html.DisplayFor(modelItem => item.StageManager)
</div>
<div class="editor-label">
@Html.DisplayFor(modelItem => item.Ganre)
</div>
<div class="editor-label">
@Html.DisplayFor(modelItem => item.Summary)
</div>
<div class="rent" id="rent">
@if (item.Rented.Equals(true))
{
<label>Rented</label>
}
else
{
@Ajax.ActionLink("Rent",
"Rent",
"Subscription",
new { id = item.ID },
new AjaxOptions()
{
UpdateTargetId = "rent",
OnComplete = "onAjaxComplete",
HttpMethod = "post",
})
}
</div>
</article>
</th>
</tr>
</table>
</li>
}
</ul>
感谢。