Im currently working on an MVC applicaiton that performs a sequence of steps listed below.
1. User performs a search from the search page which results in the action Search being invoked in the SearchController.
2. The Search action performs filtering and renders the search data in the Search.cshtml (This view supports edit over the searched results.)
3. When the user clicks on the edit link, the Edit action is invoked in the EditController.
4. The Edit action selects the record and renders it in the Edit.cshtml. (This view supports Save and Cancel.)
So heres the question. Within the Edit.cshtml if the user clicks Cancel, the application should show the filterd results back. The issue is passing the filter critera back from the Edit.cshtml to the SearchController's Search action. The point being that
Edit.cshtml would not have any idea about parameters/filter criteria that was passed when the initial search was performed.
Based on your experience what would be the best mechanisum to store the filter criteria (which is a view-model object) in such a senario?
Alternatives at hand would be to use cookies or session, but i assume there would be a much cleaner approch or implementation. Your valuable thoughts are much appriciated.
I think what you can do is build a ajax based approach.
Have a main view say index. Have three divs one below other first for the search criteria and search button, second for grid, and third for edit.
Put your search criteria first section. Implement ajax form in the first section and give the target control to the second div. This will display the content of the result in the second div. Now if you want to hide the search criteria. You can write a script
in the search result view to hide the first div. Now on click of a row in the table implement an ajax action link with target as third div. Same like in result div, if you want to hide the result while editing, add a script in the edit view to hide the result
view. On cancel button of the edit view implement javascript just to show the middle div back.
Thanks & Regards
Anup Das Gupta
Mark as Answer if you feel so. Visit My Blog
praneeth wic...
Member
24 Points
6 Posts
Maintaining data between multiple views.
Apr 27, 2012 09:38 AM|LINK
Hi All,
Im currently working on an MVC applicaiton that performs a sequence of steps listed below.
1. User performs a search from the search page which results in the action Search being invoked in the SearchController.
2. The Search action performs filtering and renders the search data in the Search.cshtml (This view supports edit over the searched results.)
3. When the user clicks on the edit link, the Edit action is invoked in the EditController.
4. The Edit action selects the record and renders it in the Edit.cshtml. (This view supports Save and Cancel.)
So heres the question. Within the Edit.cshtml if the user clicks Cancel, the application should show the filterd results back. The issue is passing the filter critera back from the Edit.cshtml to the SearchController's Search action. The point being that Edit.cshtml would not have any idea about parameters/filter criteria that was passed when the initial search was performed.
Based on your experience what would be the best mechanisum to store the filter criteria (which is a view-model object) in such a senario?
Alternatives at hand would be to use cookies or session, but i assume there would be a much cleaner approch or implementation. Your valuable thoughts are much appriciated.
-Praneeth
ossprologix
Member
394 Points
128 Posts
Re: Maintaining data between multiple views.
Apr 27, 2012 11:02 AM|LINK
hi,
save it in hidden fields in page or render it into json object. bind it to model in controller action
hope this helps
asteranup
All-Star
30184 Points
4906 Posts
Re: Maintaining data between multiple views.
Apr 27, 2012 11:16 AM|LINK
Hi,
I think what you can do is build a ajax based approach.
Have a main view say index. Have three divs one below other first for the search criteria and search button, second for grid, and third for edit.
Put your search criteria first section. Implement ajax form in the first section and give the target control to the second div. This will display the content of the result in the second div. Now if you want to hide the search criteria. You can write a script in the search result view to hide the first div. Now on click of a row in the table implement an ajax action link with target as third div. Same like in result div, if you want to hide the result while editing, add a script in the edit view to hide the result view. On cancel button of the edit view implement javascript just to show the middle div back.
Anup Das Gupta
Mark as Answer if you feel so. Visit My Blog