Hack Forums
[C#] ASP.NET Filtering - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [C#] ASP.NET Filtering (/showthread.php?tid=6118050)



ASP.NET Filtering - Jake Johnson - Oct 27, 2020

I am trying to finish this project where the user can select a color from a dropdown list and then press the filter button. Once they press the filter button the view changes so the page refreshes and only shows pictures with those colors. I need to do this by finding the matching color ID from the database to the user-selected color from the dropdown menu.


Here is the dropdown menu I am using

[Image: Xg0CUCg.png]


Here is my code I have so far that does not work. When I hit the filter button the page refreshes but it is exactly the same and shows all the same pictures as before instead of just one color. I think I am either missing something or going wrong in my query to the database. the variable uColor is set up to get the user selection from the dropdown menu.

[Image: qb6iU1A.png]

Any help would be appreciated.


RE: ASP.NET Filtering - itcorp - Oct 28, 2020

(Oct 27, 2020 01:48 PM)JakeFPS Wrote:  I am trying to finish this project where the user can select a color from a dropdown list and then press the filter button. Once they press the filter button the view changes so the page refreshes and only shows pictures with those colors. I need to do this by finding the matching color ID from the database to the user-selected color from the dropdown menu.


Here is the dropdown menu I am using

[Image: Xg0CUCg.png]


Here is my code I have so far that does not work. When I hit the filter button the page refreshes but it is exactly the same and shows all the same pictures as before instead of just one color. I think I am either missing something or going wrong in my query to the database. the variable uColor is set up to get the user selection from the dropdown menu.

[Image: qb6iU1A.png]

Any help would be appreciated.

This can be overcome in several ways very simple,in your controller you have POST and GET action unless you use one action for post and get which, as far as I can see, is not the case here.
So for your simple solution would be to set ViewBag or ViewData on post and then in get check if there are any criteria which should be respected if it really exists and if there is no criteria display standard output on get.