简体   繁体   中英

How to save page Filter state in MVC

I have website asp.net MVC 5 application, I have a question about best practices using a filter in the page

What's the issue:

I have an Employer page that has a filter (id, name, status, page (using PageList)) EmployerController And Employee page that has a filter of (id, name, status, page (using PageList)) EmployeeController

every employer has employees and the issues are to save employer filter when I getting back from an employee to employer contoller

For Example: in Employer page 4 I clicked on employer 123 and it's gone to employees page that relevant to him when I went back to the employer's page (i have a button for that) isn't refreshing the page and go to employer page 1 instead of 4

What I do

I starting to pass parameters for an employer to an employee that will pass back when I click on the go back button but it's a lot of passing because employers have a page to so on every page I need to pass params/object

is there any best practices for that kind of problem for storing the filter from one controller when i calling another or its all custom made

thanks

I Think about a good idea of using Session for that case

it will be a couple of const that will be used in sessions

public static class Sessions {
public static const string Page = "Page";
}

in the view i will set the value

Session[Sessions.Page] = this.page;

and if i click on the return button i will be getting to the function BackFromView that will be in the controller

that function will init filter from the session and redirect it to the index page.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM