Iv created an editor template for the boolean type. And it works fine in all modern browsers expect IE8 where any value changes seem to be lost when they are posted to the server.
I have read there are 'issues' with MVC checkboxs retaining their values, and as a result the Html.CheckBox helper includes a hidden field on the page to store the actual value of the checkbox. This is where my issue is, this is not being kept in sync with the checkbox in IE8.
Any ideas on fixing this?
Here is the template:
<script runat="server">
private bool? Value {
get {
bool? value = null;
if (ViewData.Model != null) {
value = Convert.ToBoolean(ViewData.Model,
System.Globalization.CultureInfo.InvariantCulture);
}
return value;
}
}
</script>
<%if(ViewData.ModelMetadata.ShowForEdit){%>
<%= Html.CheckBox("", Value ?? false, new { @class = "check-box" })%>
<%}
else if (ViewData.ModelMetadata.ShowForDisplay)
{%>
<%= Html.CheckBox("", Value ?? false, new { disabled = "disabled", @class = "read-only" })%>
<%}%>
There are other questions that broach this subject but not in the context of an editor template where the name of the html element is assigned based on the object hierarchy.