5.1 MVC Passing Checked as a Parameter

This forum allows users to post and respond to "How Do I Do ....." questions. The information contained in this forum has not been validated by K-Rise Systems and, as such, K-Rise Systems cannot guarantee the accuracy of the information.
shalomsims
Posts: 38
Joined: March 16th, 2022, 1:04 pm
Contact:

5.1 MVC Passing Checked as a Parameter

Unread post by shalomsims »

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.

CheckList
CheckList

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.
Screenshot 2022-10-05 185204.png
Parameters
Screenshot 2022-10-05 185204.png (21.78 KiB) Viewed 524 times
Parameters
Parameters
Screenshot 2022-10-05 185204.png (21.78 KiB) Viewed 524 times

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.

Here is my CheckBox control on my page and the button with the Event
Here is my CheckBox control on my page and the button with the Event


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.

ButtonEvent
ButtonEvent


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.
word count: 390

Tags:
Post Reply