I have a dialog popup form that has search button, I used ajax to call an action method whenever search is clicked. The method gets the data from the db based on what filter the user enters, then the action method returns a partial view that will display the webgrid. My problem is that when it displays the first page of the webgrid fine, but if I go to the next page the webgrid disappears. Controller
[HttpGet]
public ActionResult Index()
{
return View();
}
[HttpPost]
public ActionResult SubscriberLookUp(Member filter)
{
Member model = new Model();
//retrieve data from db based on filter and store result in a session
model = (Member)Session["UserSession"];
return PartialView("MemberGrid", model);
}
View:
<div id="ASGrid">
</div>
<script>
$(document).ready(function () {
$("#ASearchbtn").click(function () {
var ASData = $("#AdvanceSearchForm").serialize();
$.ajax({
type: "POST",
url: "/SearchPayment/SubscriberLookUp",
data: ASData,
datatype: "html",
cache: false,
success: function (response) {
$("#AdvSearch").modal("hide");
$('#ASGrid').html(response);
},
complete: function () {
$("#AdvSearch").modal("hide");
}
});
})
})
Please help, I don't know what I'm doing wrong or what I'm not doing. My guess is that since the ajax call is for the search button only it will only display the initial result (first page) So I thought of changing my SubscriberLookup method to return View(model) and then create another method in my controller:
public ActionResult GetGrid()
{
Member model = (Member)Session["UserSession"];
return PartialView("MemberGrid", model);
}
then create another ajax call in my main view:
function GetGrid(){
$.ajax({
type: "POST",
url: "/SearchPayment/GetGrid",
datatype: "html",
cache: false,
success: function (response) {
$("#AdvSearch").modal("hide");
$('#ASGrid').html(response);
},
complete: function () {
$("#AdvSearch").modal("hide");
}
});
}
But it's not working, it doesn't seem to be making the second ajax call.
Also another question, can I do [HttpPost] on a method that is not ActionResult?