ASP.net
Awesome
Learn
Forum
Buy
Demos
Sign In
☾
☀
Switch to
Dark
Light
Mode
this site works best with javascript enabled
Ask Question
Bind grid parameter to a checkbox
Title:
B
I
{code}
?
I have a grid and above that some search parameters. One of those parameters is a checkbox. As is known in razor, checkboxes created with @Html.Checkbox automatically generate a hidden field and some nifty trick is done in passing the actual boolean representating the checkbox to the controller. However when using it to be a parent to a grid, this does not work. Example: @(Html.Awe().Grid("Grid") .Columns( new Column {Name = "SomeColumn", Sortable = true, Width = 100, Header = "Datum", Sort = Sort.Desc}, .... ....) .Parent("bookingDate", "bookingDate") .Parent("displayFull", "displayFull") In the form above it I have: Display also fully booked items? @Html.CheckBox("displayFull", false) Now no matter if the checkbox is checked or not, in the controller the parameter displayFull (type bool?) is always true. Is there a way to bind the checkbox to the grid and also to pass the correct value to the controller. I believe I can fake somethings using javascript, but I rather not.
Save Changes
Cancel
mounhim
asked at 29 Jan 2014
Answers
B
I
{code}
?
Html.Checkbox generates an input type=checkbox with value = true and a hidden input with value = false (both with same name), if the checkbox is not checked it's value isn't submitted in a form post (the trick) in js value of the checkbox is always "true", but it's checked state can differ you could use an Awe().AjaxCheckboxlist with one item instead or create a checkbox with a hidden input and on checkbox click you change the value of the hidden input and trigger change on it, and you make the hidden input the parent
Save Changes
Cancel
Omu
answered at 29 Jan 2014
I have tried to use the Awe Ajax Checkbox list with one item. But the strange thing is that the checkbox appears on top of the label. I cant get it next to the label as in the demo app.
at 30 Jan 2014
mounhim
Solved it. Other css had label with display block. Thanks for the help
at 30 Jan 2014
mounhim
please
Sign In
to leave an answer
By accessing this site, you agree to store cookies on your device and disclose information in accordance with our
cookie policy
and
privacy policy
.
OK