if you have tried to serialize a CheckBoxFor from MVC to JSON, you will notice that you get two inputs, and it can mess up the data you are sending
public static string GetPropertyName<TModel, TValue>
MemberExpression body = exp.Body as MemberExpression;
if (body == null)
UnaryExpression ubody = (UnaryExpression)exp.Body;
body = ubody.Operand as MemberExpression;
public static MvcHtmlString CheckBoxForJson<
TModel, TValue>(this HtmlHelper<TModel> helper,
Expression<Func<TModel, TValue>> expression)
string propName = GetPropertyName(expression);
string html = "<input type=\"checkbox\" name=\""
+ propName + "\" id=\""
+ propName + "\" value=\"true\" />";
And use it like this:
@Html.CheckBoxForJson(x => x.SomeBool)
The reason for the 'true' is because otherwise it will always pass as false since 'on' is not a bool value (html default).