Please feel free to add more details to anything I might have missed in this Tips post. I'm still in the learning stages and I'm many newer developers will be able to benefit from this.
Sometimes while making a page we may want to pass whether or not an row is checked or not to a controller event. Say, for example I am trying to add items to an order. I have a list of items but I only want to add a few specific ones to my cart.
To set this up we created a controller for adding items to the cart. The controller takes an array as a parameter (because you can select one or more items to be moved to the cart). CheckBox is one of those parameters. We want to send all the values into the controller, then filter on whether the item is checked or not.
From here we then go to our Main view and setup the event. Here we add an event to a button and the really cool thing here is that because CheckBox is a CheckBox control, in the event setup we can specify if the parameter's value we want to pass in is a boolean of whether it is checked or not or the value of the checkbox. The latter option is very handy for a different scenario.
Say, if I had 3 checkboxes that I wanted to do different functions with depening on which combination of checkboxes are selected. I can pass in a value instead that would then be verified in some other logic to do some other thing. In this case however, we just need to know if the CheckBox is checked or not by the user when the controller is called.
The last image was just something very helpful to me as a learning developer. I'm really glad the feature was implemented because it was a little tricky at first to learn how to pass in whether or not the control was selected for each row returned in the list.
5.1 MVC Passing Checked as a Parameter
-
- Posts: 38
- Joined: March 16th, 2022, 1:04 pm
- Contact: