我在部分视图中使用Grid.mvc时遇到问题。当我在View中使用grid.mvc时,它正常工作,但是当我在局部视图中使用时,grid.mvc无法进行分页,过滤......有什么想法吗?非常感谢你! 这是我的代码:
<!-- Index.html -->
@{
ViewBag.Title = "ABC";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<div class="row">
<div class="col-xs-9 col-lg-10">
<div class="box box-primary">
<div class="box-header with-border"></div>
<div class="box box-body">
<div class="row">
<div class="col-xs-12 col-lg-12">
<div id="products"></div>
</div>
</div>
</div>
</div>
</div>
</div>
<script>
$(function() {
$.ajax({
url: '@Url.Action("GetProducts", "Equipment")',
dataType: "html",
type: "GET",
cache: false,
contentType: 'application/html; charset=utf-8',
success: function (data) {
$("#products").html(data);
},
error: function (xhr) {
alert(xhr);
}
});
});
</script>
<!--Partial view-->
@using GridMvc.Html
<script src="@Url.Content("~/Content/Scripts/gridmvc.min.js")"></script>
<script src="@Url.Content("~/Content/Scripts/jquery-1.10.2.min.js")"></script>
@Html.Grid((IEnumerable<Model.ViewModels.EquipmentModel>)ViewBag.ListEquipment).Named("ast").Columns(columns =>
{
columns.Add(c => c.Serial_No).Titled("Số serial").Filterable(true).SetWidth(100).Sortable(true);
columns.Add(c => c.Name).Titled("Tên thiết bị").Filterable(true).SetWidth(250).Sortable(true);
}).WithPaging(10).Sortable(true)
<script src="~/Content/Scripts/gridmvc.js"></script>
<!-- Controller -->
public class EquipmentController : BaseController
{
string strError = "";
// GET: Equipment
public ActionResult Index()
{
return View();
}
public ActionResult GetProducts(string ID)
{
var model = getEquipmentByID(Convert.ToInt16(ID)); //Get data
ViewBag.ListEquipment = model;
return PartialView("GetProducts", model);
}
}
答案 0 :(得分:0)
所以你只需要在调用后重新实例化网格,在ajax中使用“success”方法中的$(".grid-mvc").gridmvc();
答案 1 :(得分:0)
我在局部视图中将ajax与网格一起使用。对于分页,我在主视图中创建了一个函数,然后编辑了局部视图_GridPager.cshtml以在单击时调用我的函数。该函数再次调用Ajax函数,该函数只会加载正确的页面。
$.ajax({
type: "POST",
url: "http://ABC?grid-page=" + myPage,
data: mydata,
success: successFunc,
error: errorFunc
});
通过上述Grid实例化解决了我的分页CSS问题。