Radio button does not reflect model value
I have a Kendo Grid for a class and for that class I created an editor template to create a radio button for one of the fields.
This switch does not reflect the value of the property and always false
, although I checked the value by printing it on the form and I'm pretty sure it does true
. If I set a default value for this field, the radio button will reflect this value regardless of the actual value of the field.
I should note that I am using the client template to display the text for this field and it works great.
This is the grid:
@(Html.Kendo().Grid<Class>()
.Name("Grid")
.Columns(columns =>
{
columns.Bound(x => x.BActive).ClientTemplate("#= BActive ? 'Open':'Close' #");
/// removed for brevity
})
.Editable(editable => editable.Mode(GridEditMode.PopUp))
.DataSource(ds => ds.Ajax()
.Model(model => {
model.Id(x => x.SWhCode);
model.Field(x => x.BActive).DefaultValue(true);
})
)
)
And these are the lines that create the radio button inside editorTemplate
:
<label>
@Html.RadioButtonFor(x => x.BActive, true, new { @class = "radio-inline" }) Open
</label>
<label>
@Html.RadioButtonFor(x => x.BActive, false, new { @class = "radio-inline" }) Close
</label>
source to share
bool
the type will show up on a client like this
true => True
false => False
Are you trying to validate your element in HTML? You will see that the value is bool
converted to capizeize string
. To overcome this, you need to change true
and false
to switch the type string
too.
Your view code should look like this
<label>
@Html.RadioButtonFor(x => x.BActive, "true", new { @class = "radio-inline" }) Open
</label>
<label>
@Html.RadioButtonFor(x => x.BActive, "false", new { @class = "radio-inline" }) Close
</label>
source to share