自定义表单提交筛选分页怎么做_如何使用MVC在自定义分页中保留数据(表单)?...

I have a grid (list generated using scaffolding option) with search criteria. And I created paging concept. I entered search criteria data and search, after post back, I retained the form data using TempData. But, if I click page numbers in grid, the form data not retained and also the grid also getting refreshed.

Is there any way to retain data on pagination?

Thanks!

解决方案

I added a hidden field dynamically within the form using JavaScript. The page number stored in hidden field, when the user click page number, then submit the form. It is working well without any issue.

Paging:

@j

Javascript:

$(function () { //Page Load - Create hidden field, if search button found

if ($("#search")) // Button id

{

var element = document.createElement("input");

element.type = "hidden";

element.id = "currentPage";

element.name = "currentPage";

element.value = '@TempData["Page"]';

if (isNaN(element.value)) element.value = "1";

$(to).parent().append(element);

}

});

function navigateTo(field, url)

{

$("#currentPage").val(field.innerText);

if (isNaN($("#currentPage").val()))

{

location.href = url;//This is for direct url, ie. no search form

}

else

{

$("form").action = url;

$("form").submit();

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值