-I have a center filter dropdown on index page cshtml.cs and it will show the respective audits created for that selected center
-After the filtered audits are populated, we select on editing the audit to select yes or no which goes to activity page
-once it goes to activity page, the center filter parameter is going away, so when we go back to the the audit lists it is going to all audits instead of filtered audits.
-how to restore the selected center value from dropdown to activity page?
I tried setting this in Audit page TempData["FilterCenterAudit"] = AuditCenterId;(AuditCenterId is value selected form dropdown)
Tuhin PaulPosted Apr 25, 2023, 6:27 AM
One potential disadvantage of the approach I suggested is that TempData only retains data for a single redirect request. If the user navigates away from the activity page and then returns to the audit list page, the TempData value will have been lost and the audit list page will not be filtered by the previously selected center. Another potential disadvantage is that TempData is stored in session state, which can have implications for scalability and performance if large amounts of data are stored in it. In addition, storing data in TempData for too long can also result in session state becoming bloated and slow down the application. It's important to keep in mind that TempData should be used sparingly and only for short-term storage of small amounts of data.
Tuhin PaulPosted Apr 25, 2023, 6:25 AM
Imagine you have an ASP.NET web application that tracks employee training records. The index page of your application has a dropdown menu to filter the training records by department. When a department is selected, the page displays the corresponding training records for that department. When you select a training record to edit on this page, it redirects you to the activity page where the department filter parameter is lost. As a result, when you return to the training records list page, it displays all training records instead of the filtered records for the selected department. To retain the selected department value from the dropdown on the activity page, you can use TempData to store the selected department value like this: "TempData["FilterDepartmentTraining"] = DepartmentId;" (where DepartmentId is the value selected from the dropdown). Then, on the training records list page, you can check if TempData contains the "FilterDepartmentTraining" key and use its value to filter the records accordingly. For example:
With this code, if the "FilterDepartmentTraining" key exists in TempData and its value is not null or empty, it filters the training records by the selected department before returning the view.
Amit MohantyPosted Apr 25, 2023, 3:56 AM
One way to restore the selected center value from the dropdown to the activity page is by passing the selected center value as a query parameter in the URL when navigating from the index page to the activity page.
In the index page, you can append the selected center value to the URL as a query parameter when navigating to the activity page. For example, the URL might look like this:
/activity?centerId=You can then retrieve the selected center value from the query parameter in the activity page using the Request object. For example, in C#:
string centerId = Request.Query["centerId"];Once you have retrieved the selected center value, you can use it to filter the audits on the activity page.
To make sure that the selected center value is preserved when navigating back to the index page, you can also append it to the URL as a query parameter when navigating back. For example:
/index?centerId=Then in the index page, you can retrieve the selected center value from the query parameter and use it to pre-select the center filter dropdown.