Ashish
Ashish

Reputation: 31

Paging is not working on GridMvc its Reloading the page

I have two method httpget as

 public ActionResult MiReport()
 {
 return View();
 }

And httppost as

public ActionResult GetReportView(string startdate,string enddate) {
    ReportModel Obj = new ReportModel( startdate, enddate );
    return PartialView("GetReportView",Obj );
}

I am binding grid as

@using GridMvc.Html
<div class="col-md-12">
<h4><strong>REPORT</strong></h4>
@Html.Grid(Model.lstReport).Columns(columns => {
    columns.Add(c => c.rep).Titled("REP");
    columns.Add(c => c.businessName).Titled("BUSINESS NAME");
    columns.Add(c => c.contactNmae).Titled("CONTACT NAME");
}).WithPaging(10)
</div>

I am showing it on View its loading the first 10 row fine but when I am clicking on paging button its calling the Get method and page is getting reloded.

Upvotes: 2

Views: 1087

Answers (1)

anu
anu

Reputation: 315

You need to have your grid be given a name like this (Index.cshtml):

.WithPaging(10, 10, "grid1")

Now in the Index method change it to :

 public ActionResult Index(String grid1 = "")

Now when you click on the page, you will see page number in the url as grid1=3,this will be read into parameter grid1 of Index method.

Now in this method check:-

if (!String.IsNullOrEmpty(grid1))
{
//my grid was populated based on PersonnelId selected in some dropdown on the view.You can use the variable in which you stored your key.
 id = TempData["TimeOffPersonnelID"].ToString();
}

Hope this helps!!

Upvotes: 0

Related Questions