Asp.net MVC implements automatic page jump after page number is selected through the drop-down box

Source: Internet
Author: User

Because we support automatic page jump after page selection through the drop-down box, it is a bit like webform's autopostback, and we also need to solve a problem to solve the problem of automatic page jump after selection, we need to carry the previous query conditions and cannot jump after the page is displayed, the query condition disappears.

The connection generated by the tag with a hidden a tag saves the current query condition, and the number of other pages is displayed as "* pageindex *. When we select the drop-down box to skip the page, replace it with the selected value. this "* pageindex * and jump to the current href solves the above problem.

UpperCode

<Text> jump to </text>
<Select id = "pageselect" onchange = "selectchange ()">
@ For (INT I = 1; I <= @ model. totalpagecount; I ++)
{
VaR selected = "";
If (I = model. currentpageindex)
{
Selected = "selected = 'selected '";
}
<Option value = "@ I" @ selected> @ I </option>
}
</SELECT>

{
Dict ["pageindex"] = "* pageindex *";
}
<A style = "display: none" id = "pagelink" href = "@ URL. routeurl (dict)"> </a>
//
<SCRIPT type = "text/JavaScript">

Function selectchange (){
VaR pageselect = Document. getelementbyid ("pageselect ");
VaR pageselectvalue = pageselect. Options [pageselect. selectedindex]. value;

VaR linkdom = Document. getelementbyid ("pagelink ");
VaR href = linkdom. href;
Href = href. Replace ("* pageindex *", pageselectvalue );

Window. Location = href;

}
</SCRIPT>

<Text> page </text>
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.