随便举了个例子。
@model IEnumerable<Ajax.Models.nmb>
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
<p>
@Html.ActionLink("Create New", "Create")
</p>
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.name)
</th>
<th>
@Html.DisplayNameFor(model => model.age)
</th>
<th>
@Html.DisplayNameFor(model => model.lesson)
</th>
<th></th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.name)
</td>
<td>
@Html.DisplayFor(modelItem => item.age)
</td>
<td>
@Html.DisplayFor(modelItem => item.lesson)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id=item.id }) |
@Html.ActionLink("Details", "Details", new { id=item.id }) |
@Html.ActionLink("Delete", "Delete", new { id=item.id })
</td>
</tr>
}
</table>
// GET: nmbs/Details/5
public ActionResult Details(int? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
nmb nmb = db.nmb.Find(id);
if (nmb == null)
{
return HttpNotFound();
}
return View(nmb);
}
这些代码都是MVC自动生成的,没什么好讲,我只是提供了一个模型。
当你点击Details的时候,他的原理是直接传递一个model的参数,然后跳转至一个新的页面。
现在我想实现的是,点击Details后,页面不进行跳转,而是进行局部刷新,将详情在该页面下方展示出来。
请最好能给出详情的代码和过程,我原来打算用Ajax.beginform来实现,但不知道哪个环节出了差错,老是出现各种奇怪的意外,希望能够得到坛友的帮助。