Home WebGrid causing page refresh on server side Paging / Filtering / Sorting in ASP.NET MVC
Reply: 0

WebGrid causing page refresh on server side Paging / Filtering / Sorting in ASP.NET MVC

user3214
1#
user3214 Published in May 27, 2018, 3:33 am

I am working on binding data to webgrid in mvc and performing server side paging,filtering and sorting which i have done successfully but the problem which i am facing is whenever i am trying to perform any server side action like paging,sorting or filter these three functions are working fine but the page is getting refreshed or reloaded, for example their is a textbox above the grid and i have written some text in that textbox, after performing pagination the textbox is getting cleared. I used to work on webforms before, their i use to work with update panels but how can i achieve this in MVC.

Following is Code and some attachment as well:

Controller:

public ActionResult WebGrid(int page=1,string sort = "", string sortdir = "", string search = "")
    {
        var list = new List<Product>();
        int DisplayLength = 10;
        int DisplayStart = (page * DisplayLength) - DisplayLength;
        list = pad.GetPrdListInChunks_1(DisplayLength, DisplayStart, sort, sortdir,search);
        ViewBag.TotalRows = int.Parse(list[0].TotalCount);
        ViewBag.Search = search;
        return View(list);
    }

View:

@model List<NorthwindApplication.Models.Product>
@{
Layout = "~/Views/Shared/_Layout.cshtml";
WebGrid grid = new WebGrid(canPage: true, rowsPerPage: 10);
grid.Bind(Model, rowCount: ViewBag.TotalRows, autoSortAndPage: false);

}

<div class="container">
<h2>Product List</h2>
@using (Html.BeginForm("WebGrid", "Product", FormMethod.Get))
{
    <div class="row">

        <div class="col-sm-4">
            <input type="text" name="search" value="@ViewBag.Search" class="form-control" />
        </div>
        <div class="col-sm-2">
            <button type="submit" style="display:none;" value="Search" class="btn btn-primary">Search</button>
        </div>

    </div>
}
<div class="row">

    @grid.Table(
         tableStyle: "table table-bordered",
         columns: grid.Columns(
             grid.Column(columnName: "ProductID", header: "ProductID"),
             grid.Column(columnName: "ProductName", header: "ProductName"),
             grid.Column(columnName: "SupplierID", header: "SupplierID"),
             grid.Column(columnName: "SupplierName", header: "SupplierName"),
             grid.Column(columnName: "SupplierCountry", header: "Country"),
             grid.Column(columnName: "CategoryName", header: "CategoryName"),
             grid.Column(columnName: "QuantityPerUnit", header: "QtyPerUnit"),
             grid.Column(columnName: "UnitPrice", header: "UnitPrice")
         )
     )

    <div class="row">
        <div class="col-sm-6">
            @grid.PagerList(mode: WebGridPagerModes.Numeric, paginationStyle: "pagination pagination-small pagination-right")
        </div>
    </div>

    @*@Html.Hidden("dir", grid.SortDirection)
        @Html.Hidden("col", grid.SortColumn)*@

</div>

While performing paging

after performing paging

Thank You

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.30338 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO