-1

We have a view where there is a CheckBox that we are setting from a model property.

@using (Ajax.BeginForm(new AjaxOptions { HttpMethod = "get", InsertionMode = InsertionMode.Replace, UpdateTargetId = "content_list", Url = Url.Action("IndexList", "UsersAdmin", new { id = "formSearch" })))
{
    .......(some code)
    <div id="content_list">
        @Html.CheckBoxFor(model => model.SearchAll)
    </div>
    <div id="content_list">
        @Html.Partial("_List", Model)
    </div>
}

Depending on the first load the checkbox is checked or not. This works great, no problems.

As you see the CheckBox is inside an Ajax form that refreshes the partial list that contains a list.

In the scripts we have:

    $("#SearchAll").change(function() {
        jQuery('#SearchAll').closest('form').submit();
    });

When the CheckBox first load unchecked there is no problem. We check it and uncheck it and always the controller action is called.

The problem is when we first load the CheckBox checked (true value). In this case when we uncheck the checkbox it goes to the javascript change function but it doesn't call the controller action. When we check it back again it works good. So in this case it only works when you are checking the checkbox but not while unchecking..

We have tried many things but it seams weird...maybe somebody knows about this issue.

Thanks in advance.

John Mathison
  • 904
  • 1
  • 11
  • 36
  • What do you have in console? (F12 button in browser.) Any Errors? Show your controller also please – teo van kot May 04 '16 at 09:47
  • No errors, in fact I have checked and it passes everywhere in any case. The only problem is when it is checked at first that does nothing in the controller (server), but it executes the javascript fine. – John Mathison May 04 '16 at 09:51
  • do you have only one form on your page? Could be that `.closest('form')` returns other form – teo van kot May 04 '16 at 09:55
  • Yes, we also have tried to click the submit button or call the form directly. Same result. It is like when we go from checked to unchecked it doesn't want to execute the Ajax call. – John Mathison May 04 '16 at 09:58
  • We have discovered that when unckeched even the search button or any of the buttons within the form stop working until you check the checkbox again to checked. – John Mathison May 04 '16 at 10:22

1 Answers1

0

There wasn't a problem with the CheckBox itself, there was a control inside de form that was giving an incorrect value when the CheckBox was checked, so the form wasn't validating and also wasn't executing the ajax call.

Sorry guys and thanks for your answers.

I hope at least this could help someone with similar errors.

John Mathison
  • 904
  • 1
  • 11
  • 36