Webgrid paging always sending get request in asp.net mvc razor
On page load view is sending a get request to controller and based on default values for textbox studentsIdFrom(1) and studentsIDTo(30) webgrid is showing data of 10 students. Then based on filteration Let's say user filled value for textboxes studentsIdFrom(15) and studentsIDTo(55) and then user click on go button then a post request is sent to controller and data is shown with paging (10 students data per page) . But when I click on page 2 it shows data that is in 2nd page of default data. It means it is sending a get request to controller.
My Controller
using StudentData.Models;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Dapper;
namespace StudentData.Controllers
{
public class StudentController : Controller
{
// GET: Student
[HttpGet]
public ActionResult Index()
{
int idFrom = 1;
int idTo = 30;
using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["StudentData"].ConnectionString))
{
conn.Open();
string sqlQuery = "Select * From Student WHERE Id >= @idFrom and Id <= @idTo";
var resultSet = conn.Query<Student>(sqlQuery).ToList();
return View(resultSet);
}
}
[HttpPost]
public ActionResult Index(int idFrom, int idTo)
{
using (IDbConnection db = new SqlConnection(ConfigurationManager.ConnectionStrings["StudentData"].ConnectionString))
{
string sqlQuery = "Select * From Student WHERE Id >= @idFrom and Id <= @idTo ;";
var resultSet = db.Query<Student>(sqlQuery).ToList();
return View(resultSet);
}
}
}
}
My View
@model IEnumerable<StudentData.Models.Student>
@using (Ajax.BeginForm("Index", "Student", new AjaxOptions { HttpMethod = "POST" }))
{
<table>
<tr>
<td>ID(s): </td>
<td>
From:<input type="number" id="idFrom" name="idFrom" />
To:<input type="number" id="idTo" name="idTo" />
</td>
<td>
<a href="#">Clear</a>
</td>
<tr>
<td align="right">
<input type="submit" value="Go" />
</td>
</tr>
</table>
}
<b>@Model.Count()</b>
@{
Layout = null;
WebGrid grid = new WebGrid(source: Model, canSort: true, canPage: true, rowsPerPage: 10);
grid.Pager(WebGridPagerModes.All);
@grid.GetHtml(htmlAttributes: new { id = "grid" },
headerStyle: "webgrid-header",
columns: new
{
grid.Column( "ID" , "ID" , canSort:true ),
grid.Column( "Name" , "Name" , canSort:true ),
grid.Column( "DOB" , "DOB" , canSort:true ),
grid.Column( "Dept" , "Dept" , canSort:true )
}
)
}
My Model
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace StudentData.Models
{
public class Student
{
public int ID { get; set; }
public string Name { get; set; }
public DateTime DOB { get; set; }
public string Dept { get; set; }
}
}
On Page Load it's showing data of first 10 students with 3 page symbol(1 2 3) at bottom. when i click on page 2 it shows data of students from id 11 to 20. Now i fill the values for textboxes idFrom(15) and idTo(60) and click on Go button. Now its shows data from students id 15 to 24 with 5 page symbols(1 2 3 4 5 ) at bottom and when i click on page 2 it shows data of id from 11 to 20. but i want data of id from 25 to 34 on this click.
c# asp.net-mvc razor webgrid
add a comment |
On page load view is sending a get request to controller and based on default values for textbox studentsIdFrom(1) and studentsIDTo(30) webgrid is showing data of 10 students. Then based on filteration Let's say user filled value for textboxes studentsIdFrom(15) and studentsIDTo(55) and then user click on go button then a post request is sent to controller and data is shown with paging (10 students data per page) . But when I click on page 2 it shows data that is in 2nd page of default data. It means it is sending a get request to controller.
My Controller
using StudentData.Models;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Dapper;
namespace StudentData.Controllers
{
public class StudentController : Controller
{
// GET: Student
[HttpGet]
public ActionResult Index()
{
int idFrom = 1;
int idTo = 30;
using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["StudentData"].ConnectionString))
{
conn.Open();
string sqlQuery = "Select * From Student WHERE Id >= @idFrom and Id <= @idTo";
var resultSet = conn.Query<Student>(sqlQuery).ToList();
return View(resultSet);
}
}
[HttpPost]
public ActionResult Index(int idFrom, int idTo)
{
using (IDbConnection db = new SqlConnection(ConfigurationManager.ConnectionStrings["StudentData"].ConnectionString))
{
string sqlQuery = "Select * From Student WHERE Id >= @idFrom and Id <= @idTo ;";
var resultSet = db.Query<Student>(sqlQuery).ToList();
return View(resultSet);
}
}
}
}
My View
@model IEnumerable<StudentData.Models.Student>
@using (Ajax.BeginForm("Index", "Student", new AjaxOptions { HttpMethod = "POST" }))
{
<table>
<tr>
<td>ID(s): </td>
<td>
From:<input type="number" id="idFrom" name="idFrom" />
To:<input type="number" id="idTo" name="idTo" />
</td>
<td>
<a href="#">Clear</a>
</td>
<tr>
<td align="right">
<input type="submit" value="Go" />
</td>
</tr>
</table>
}
<b>@Model.Count()</b>
@{
Layout = null;
WebGrid grid = new WebGrid(source: Model, canSort: true, canPage: true, rowsPerPage: 10);
grid.Pager(WebGridPagerModes.All);
@grid.GetHtml(htmlAttributes: new { id = "grid" },
headerStyle: "webgrid-header",
columns: new
{
grid.Column( "ID" , "ID" , canSort:true ),
grid.Column( "Name" , "Name" , canSort:true ),
grid.Column( "DOB" , "DOB" , canSort:true ),
grid.Column( "Dept" , "Dept" , canSort:true )
}
)
}
My Model
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace StudentData.Models
{
public class Student
{
public int ID { get; set; }
public string Name { get; set; }
public DateTime DOB { get; set; }
public string Dept { get; set; }
}
}
On Page Load it's showing data of first 10 students with 3 page symbol(1 2 3) at bottom. when i click on page 2 it shows data of students from id 11 to 20. Now i fill the values for textboxes idFrom(15) and idTo(60) and click on Go button. Now its shows data from students id 15 to 24 with 5 page symbols(1 2 3 4 5 ) at bottom and when i click on page 2 it shows data of id from 11 to 20. but i want data of id from 25 to 34 on this click.
c# asp.net-mvc razor webgrid
1
It would be awesome if you could provide a Minimal, Complete, and Verifiable example.
– mjwills
Nov 22 at 12:14
Also, note that for paging scenarios,GETis generally better to use thanPOST(so bookmarking is possible). This is likely not your issue, but something to keep in mind.
– mjwills
Nov 22 at 12:14
Have you looked at Chrome Developer Tools, Network tab, to see the requests being made? Be sure to clickPreserve log.
– mjwills
Nov 22 at 12:18
Yes, I've checked it.
– RaniMittal
Nov 25 at 8:40
add a comment |
On page load view is sending a get request to controller and based on default values for textbox studentsIdFrom(1) and studentsIDTo(30) webgrid is showing data of 10 students. Then based on filteration Let's say user filled value for textboxes studentsIdFrom(15) and studentsIDTo(55) and then user click on go button then a post request is sent to controller and data is shown with paging (10 students data per page) . But when I click on page 2 it shows data that is in 2nd page of default data. It means it is sending a get request to controller.
My Controller
using StudentData.Models;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Dapper;
namespace StudentData.Controllers
{
public class StudentController : Controller
{
// GET: Student
[HttpGet]
public ActionResult Index()
{
int idFrom = 1;
int idTo = 30;
using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["StudentData"].ConnectionString))
{
conn.Open();
string sqlQuery = "Select * From Student WHERE Id >= @idFrom and Id <= @idTo";
var resultSet = conn.Query<Student>(sqlQuery).ToList();
return View(resultSet);
}
}
[HttpPost]
public ActionResult Index(int idFrom, int idTo)
{
using (IDbConnection db = new SqlConnection(ConfigurationManager.ConnectionStrings["StudentData"].ConnectionString))
{
string sqlQuery = "Select * From Student WHERE Id >= @idFrom and Id <= @idTo ;";
var resultSet = db.Query<Student>(sqlQuery).ToList();
return View(resultSet);
}
}
}
}
My View
@model IEnumerable<StudentData.Models.Student>
@using (Ajax.BeginForm("Index", "Student", new AjaxOptions { HttpMethod = "POST" }))
{
<table>
<tr>
<td>ID(s): </td>
<td>
From:<input type="number" id="idFrom" name="idFrom" />
To:<input type="number" id="idTo" name="idTo" />
</td>
<td>
<a href="#">Clear</a>
</td>
<tr>
<td align="right">
<input type="submit" value="Go" />
</td>
</tr>
</table>
}
<b>@Model.Count()</b>
@{
Layout = null;
WebGrid grid = new WebGrid(source: Model, canSort: true, canPage: true, rowsPerPage: 10);
grid.Pager(WebGridPagerModes.All);
@grid.GetHtml(htmlAttributes: new { id = "grid" },
headerStyle: "webgrid-header",
columns: new
{
grid.Column( "ID" , "ID" , canSort:true ),
grid.Column( "Name" , "Name" , canSort:true ),
grid.Column( "DOB" , "DOB" , canSort:true ),
grid.Column( "Dept" , "Dept" , canSort:true )
}
)
}
My Model
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace StudentData.Models
{
public class Student
{
public int ID { get; set; }
public string Name { get; set; }
public DateTime DOB { get; set; }
public string Dept { get; set; }
}
}
On Page Load it's showing data of first 10 students with 3 page symbol(1 2 3) at bottom. when i click on page 2 it shows data of students from id 11 to 20. Now i fill the values for textboxes idFrom(15) and idTo(60) and click on Go button. Now its shows data from students id 15 to 24 with 5 page symbols(1 2 3 4 5 ) at bottom and when i click on page 2 it shows data of id from 11 to 20. but i want data of id from 25 to 34 on this click.
c# asp.net-mvc razor webgrid
On page load view is sending a get request to controller and based on default values for textbox studentsIdFrom(1) and studentsIDTo(30) webgrid is showing data of 10 students. Then based on filteration Let's say user filled value for textboxes studentsIdFrom(15) and studentsIDTo(55) and then user click on go button then a post request is sent to controller and data is shown with paging (10 students data per page) . But when I click on page 2 it shows data that is in 2nd page of default data. It means it is sending a get request to controller.
My Controller
using StudentData.Models;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Dapper;
namespace StudentData.Controllers
{
public class StudentController : Controller
{
// GET: Student
[HttpGet]
public ActionResult Index()
{
int idFrom = 1;
int idTo = 30;
using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["StudentData"].ConnectionString))
{
conn.Open();
string sqlQuery = "Select * From Student WHERE Id >= @idFrom and Id <= @idTo";
var resultSet = conn.Query<Student>(sqlQuery).ToList();
return View(resultSet);
}
}
[HttpPost]
public ActionResult Index(int idFrom, int idTo)
{
using (IDbConnection db = new SqlConnection(ConfigurationManager.ConnectionStrings["StudentData"].ConnectionString))
{
string sqlQuery = "Select * From Student WHERE Id >= @idFrom and Id <= @idTo ;";
var resultSet = db.Query<Student>(sqlQuery).ToList();
return View(resultSet);
}
}
}
}
My View
@model IEnumerable<StudentData.Models.Student>
@using (Ajax.BeginForm("Index", "Student", new AjaxOptions { HttpMethod = "POST" }))
{
<table>
<tr>
<td>ID(s): </td>
<td>
From:<input type="number" id="idFrom" name="idFrom" />
To:<input type="number" id="idTo" name="idTo" />
</td>
<td>
<a href="#">Clear</a>
</td>
<tr>
<td align="right">
<input type="submit" value="Go" />
</td>
</tr>
</table>
}
<b>@Model.Count()</b>
@{
Layout = null;
WebGrid grid = new WebGrid(source: Model, canSort: true, canPage: true, rowsPerPage: 10);
grid.Pager(WebGridPagerModes.All);
@grid.GetHtml(htmlAttributes: new { id = "grid" },
headerStyle: "webgrid-header",
columns: new
{
grid.Column( "ID" , "ID" , canSort:true ),
grid.Column( "Name" , "Name" , canSort:true ),
grid.Column( "DOB" , "DOB" , canSort:true ),
grid.Column( "Dept" , "Dept" , canSort:true )
}
)
}
My Model
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace StudentData.Models
{
public class Student
{
public int ID { get; set; }
public string Name { get; set; }
public DateTime DOB { get; set; }
public string Dept { get; set; }
}
}
On Page Load it's showing data of first 10 students with 3 page symbol(1 2 3) at bottom. when i click on page 2 it shows data of students from id 11 to 20. Now i fill the values for textboxes idFrom(15) and idTo(60) and click on Go button. Now its shows data from students id 15 to 24 with 5 page symbols(1 2 3 4 5 ) at bottom and when i click on page 2 it shows data of id from 11 to 20. but i want data of id from 25 to 34 on this click.
c# asp.net-mvc razor webgrid
c# asp.net-mvc razor webgrid
edited Nov 26 at 13:34
asked Nov 22 at 12:13
RaniMittal
11
11
1
It would be awesome if you could provide a Minimal, Complete, and Verifiable example.
– mjwills
Nov 22 at 12:14
Also, note that for paging scenarios,GETis generally better to use thanPOST(so bookmarking is possible). This is likely not your issue, but something to keep in mind.
– mjwills
Nov 22 at 12:14
Have you looked at Chrome Developer Tools, Network tab, to see the requests being made? Be sure to clickPreserve log.
– mjwills
Nov 22 at 12:18
Yes, I've checked it.
– RaniMittal
Nov 25 at 8:40
add a comment |
1
It would be awesome if you could provide a Minimal, Complete, and Verifiable example.
– mjwills
Nov 22 at 12:14
Also, note that for paging scenarios,GETis generally better to use thanPOST(so bookmarking is possible). This is likely not your issue, but something to keep in mind.
– mjwills
Nov 22 at 12:14
Have you looked at Chrome Developer Tools, Network tab, to see the requests being made? Be sure to clickPreserve log.
– mjwills
Nov 22 at 12:18
Yes, I've checked it.
– RaniMittal
Nov 25 at 8:40
1
1
It would be awesome if you could provide a Minimal, Complete, and Verifiable example.
– mjwills
Nov 22 at 12:14
It would be awesome if you could provide a Minimal, Complete, and Verifiable example.
– mjwills
Nov 22 at 12:14
Also, note that for paging scenarios,
GET is generally better to use than POST (so bookmarking is possible). This is likely not your issue, but something to keep in mind.– mjwills
Nov 22 at 12:14
Also, note that for paging scenarios,
GET is generally better to use than POST (so bookmarking is possible). This is likely not your issue, but something to keep in mind.– mjwills
Nov 22 at 12:14
Have you looked at Chrome Developer Tools, Network tab, to see the requests being made? Be sure to click
Preserve log.– mjwills
Nov 22 at 12:18
Have you looked at Chrome Developer Tools, Network tab, to see the requests being made? Be sure to click
Preserve log.– mjwills
Nov 22 at 12:18
Yes, I've checked it.
– RaniMittal
Nov 25 at 8:40
Yes, I've checked it.
– RaniMittal
Nov 25 at 8:40
add a comment |
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53430777%2fwebgrid-paging-always-sending-get-request-in-asp-net-mvc-razor%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53430777%2fwebgrid-paging-always-sending-get-request-in-asp-net-mvc-razor%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
It would be awesome if you could provide a Minimal, Complete, and Verifiable example.
– mjwills
Nov 22 at 12:14
Also, note that for paging scenarios,
GETis generally better to use thanPOST(so bookmarking is possible). This is likely not your issue, but something to keep in mind.– mjwills
Nov 22 at 12:14
Have you looked at Chrome Developer Tools, Network tab, to see the requests being made? Be sure to click
Preserve log.– mjwills
Nov 22 at 12:18
Yes, I've checked it.
– RaniMittal
Nov 25 at 8:40