SaaS CMS has officially launched! Learn more now.

Xform Checkbox selected or not value in MVC


Do anyone know how to get if the checkbox is selected or not by the user in the XForm checkbox. I used Key/value to get the value for

the XformData. but for Checkbox its always gives empty.

Jun 25, 2013 12:46

Also experiencing this in 7.5.  

Apr 16, 2014 9:59

Did you ever solve this?

Jun 13, 2014 14:48
@using EPiServer.XForms.Parsing
@model SelectFragment

    @foreach (SelectOption selectoption in Model.Options)
        <div class="checkbox @(Model.Class.IsEmpty() ? "col-sm-12" : Model.Class)">
                <input id="@selectoption.Id" name="@selectoption.Id" type="checkbox" value="true">
                <input name="@selectoption.Id" type="hidden" value="false">

Yepp, it works with the following code.

Wish it would have been solvable with Html.Checkbox, but I guess not :)

Jun 17, 2014 17:25

This behaviour seems to be random, we got select working nicely without custom rendering but then again it started to fail. WTF?

Aug 26, 2014 17:21

Found reason for this "random" behaviour: It was a freaking dot (.) character in the checkbox option value.

In EPiServer SelectOption.Id is generated by taking SelectFragment.Reference + SelectOption.text. EPiServer renders checkboxes by default using HTML.Checkbox helper, and SelectOption.Id is passed to it as the name for the checkbox. We had dot character in our SelectOption.Text property.

Seems that dot character is dropped out from name in this rendering process, which caused the value that was sent when checkbox was selected not to match the Option name in XForm defined in EPiServer.

IMHO SelectOption.ID should be generated some other way as the Text property can contain whatever characters causing potentially problems.

So small issue and so much pain....

Aug 27, 2014 1:33

... And as a postscript: The solution Jonas presented should have worked in theory as it bypasses the HTML.Checkbox and renders checkbox directly. But then I ran to next problem with id attribute as html attribute id can only contain limited set of characters, for example spaces are not allowed. But it must be unique so to be able to use SelectOption.Id one must first escpage/clean the SelectOption.Id so that it is valid string for html id attribute.

Aug 27, 2014 1:48
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.