【发布时间】:2014-01-14 05:12:56
【问题描述】:
花了很长时间试图解决这个问题,但一无所获。 基本上,当单击操作链接时,我希望使用新页面上显示的值更新 div,但似乎无法解决问题。 这是我的代码:
@*@model PagedList.IPagedList<S00117372CA3.Product>*@
@*@model Tuple<PagedList.IPagedList<S00117372CA3.Product>, IEnumerable<S00117372CA3.Order>>*@
@model S00117372CA3.Controllers.ProductViewModel
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
<p>
@Html.ActionLink("Create New", "Create")
</p>
<table class="searchResult">
<tr>
<th>
@Html.DisplayNameFor(model => model.Products.First().ProductName)
</th>
<th>
@Html.DisplayNameFor(model => model.Products.First().Supplier.CompanyName)
</th>
<th>
@Html.DisplayNameFor(model => model.Products.First().Category.CategoryName)
</th>
<th>
@Html.DisplayNameFor(model => model.Products.First().QuantityPerUnit)
</th>
<th>
@Html.DisplayNameFor(model => model.Products.First().UnitPrice)
</th>
<th>
@Html.DisplayNameFor(model => model.Products.First().UnitsInStock)
</th>
<th>
@Html.DisplayNameFor(model => model.Products.First().UnitsOnOrder)
</th>
<th>
@Html.DisplayNameFor(model => model.Products.First().ReorderLevel)
</th>
<th>
@Html.DisplayNameFor(model => model.Products.First().Discontinued)
</th>
<th></th>
</tr>
@foreach (var item in Model.Products) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.ProductName)
</td>
<td>
@Html.DisplayFor(modelItem => item.Supplier.CompanyName)
</td>
<td>
@Html.DisplayFor(modelItem => item.Category.CategoryName)
</td>
<td>
@Html.DisplayFor(modelItem => item.QuantityPerUnit)
</td>
<td>
@Html.DisplayFor(modelItem => item.UnitPrice)
</td>
<td>
@Html.DisplayFor(modelItem => item.UnitsInStock)
</td>
<td>
@Html.DisplayFor(modelItem => item.UnitsOnOrder)
</td>
<td>
@Html.DisplayFor(modelItem => item.ReorderLevel)
</td>
<td>
@Html.DisplayFor(modelItem => item.Discontinued)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id=item.ProductID }) |
@Ajax.ActionLink("Details", "Details", new { id=item.ProductID }, new AjaxOptions { UpdateTargetId = "searchResult", InsertionMode = InsertionMode.Replace, HttpMethod = "GET" }) |
@Html.ActionLink("Delete", "Delete", new { id=item.ProductID })
</td>
</tr>
}
</table>
<div>
Page @(Model.Products.PageCount < Model.Products.PageNumber ? 0 : Model.Products.PageNumber) of @Model.Products.PageCount
@if (Model.Products.HasPreviousPage)
{
@Html.ActionLink("<<", "Index", new { page = 1})
@Html.Raw(" ");
@Html.ActionLink("< Prev", "Index", new {page = Model.Products.PageNumber - 1})
}
else{
@:<<
@Html.Raw(" ");
@:< Prev
}
@if (Model.Products.HasNextPage)
{
@Html.ActionLink("Next >", "Index", new {page = Model.Products.PageNumber + 1})
@Html.Raw(" ");
@Html.ActionLink(">>", "Index", new {page = Model.Products.PageCount})
}
else{
@:Next >
@Html.Raw(" ")
@:>>
}
</div>
<div id="searchResult">
</div>
@Scripts.Render("~/bundles/jquery")
<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.js")" type="text/javascript"></script>
【问题讨论】:
标签: c# asp.net ajax views partial-views