Click here to Skip to main content
15,078,444 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
I have a problem about use Grid.mvc in Partial View. When I use grid.mvc in View, it working normal but when I use in partial view, grid.mvc can't paging, filter... Have any idea? Thanks you very much! This is my code:


What I have tried:

<pre lang="HTML">
<!-- 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>


&lt;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);
}
});
});
&lt;/script>


<!--Partial view-->

@using GridMvc.Html

&lt;script src="@Url.Content("~/Content/Scripts/gridmvc.min.js")">&lt;/script>
&lt;script src="@Url.Content("~/Content/Scripts/jquery-1.10.2.min.js")">&lt;/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)
&lt;script src="~/Content/Scripts/gridmvc.js">&lt;/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);
}
}
</pre>
Posted
Updated 4-Oct-17 12:24pm

1 solution

/* Refresh the grid, once it is placed in the div */
$(".grid-mvc").gridmvc();
   
Comments
Member 14542576 26-Jul-19 15:02pm
   
It does not work.
I have used like below.
success: function (data) {
$('#dvData').html(data);
$(".grid-mvc").gridmvc();
modal.style.display = "block";

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900