1

In UI:

1) I have to check the ComboBox 2) As HTTPGET send the selected value of ComboBox 3) Then Uncheck the ComboBox, after execution of Controller Action Method.

Code:

 $("#Search").click(function () {
        $(".selsts").attr('checked', false);
    });

This is my JQuery to uncheck the ComboBox On Button Click "Search".

Problem:

Before sending the Value to the controller Action, the checkbox get Unchecked and hence I am not receiving the CheckBox Value.

  @using (@Html.BeginForm("GetExtMsg", "ShowMessage", FormMethod.Get))
{
    <div id="inputFields">
        <div class="inputLabel"><label><b>Search By:</b></label> </div>
    </div>


    @Html.CheckBox("Review", new { @class="selsts" })
    <label style="float: left;">Review Status</label>

    @Html.CheckBox("Corellation", new { @class = "selsts" })
    <label style="float: left;">Corellation</label>

    @Html.CheckBox("ControllerStatus", new { @class = "selsts" })
    <label style="float: left;">Controllers</label>

    @Html.CheckBox("Team", new { @class = "selsts" })
    <label style="float: left;">Team</label>

    @Html.DropDownList("ReviewsearchType", new List<SelectListItem>
        {
            new SelectListItem { Text = "Reviewed", Value = "Reviewed" },
            new SelectListItem { Text = "Review Done", Value = "Review Done" },
            new SelectListItem { Text = "Authorized", Value = "Authorized" }
        }, "Select")
    @Html.DropDownList("CorellationsearchType", new List<SelectListItem>
        {
            new SelectListItem { Text = "A", Value = "A" },
            new SelectListItem { Text = "B", Value = "B" },
        }, "Select")
    @Html.DropDownList("ControllersearchType", new List<SelectListItem>
        {
            new SelectListItem { Text = "True", Value = "True" },
            new SelectListItem { Text = "False", Value = "False" },
        }, "Select")
    <input type="submit" id="Search" value="Search" class="button_gray" />
}

JavaScript :

<script type="text/javascript">
$(function () {
    $('#ReviewsearchType').hide();
    $("#Review").change(function () {
        $('#ReviewsearchType').toggle(this.checked)
    })

    $('#CorellationsearchType').hide();
    $("#Corellation").change(function () {
        $('#CorellationsearchType').toggle(this.checked)
    });

    $('#ControllersearchType').hide();
    $("#ControllerStatus").change(function () {
        $('#ControllersearchType').toggle(this.checked)
    })

    $("#Search").click(function () {
        $(".selsts").attr('checked', false);
    });


});

Any Suggessions/Help?

10
  • If the user surfs to the page, the checkbox is always checked? Then you can just check it by default in the HTML. Commented Aug 25, 2014 at 13:29
  • for the first time after Page Load, The checkboxes are unchecked. Commented Aug 25, 2014 at 13:32
  • Unless you explicitly check them in HTML. Commented Aug 25, 2014 at 13:33
  • How to do it? I am not getting you. Commented Aug 25, 2014 at 13:34
  • Post more code, is this a full submit or is it an ajax call? Commented Aug 25, 2014 at 13:35

1 Answer 1

1

The problem is, click event fires before submit event, so you are unchecking your check-box with this code:

$("#Search").click(function () {
    $(".selsts").attr('checked', false);
});

That is why you are not getting the values to the server. Make the default state of checkbox "unchecked".

<input type="checkbox">

this will cause it to be unchecked by default, when page reloads after submit.

EDIT: full submit will usually reload the page, show me your controller code as well please. If you want to preserve the state of UI before submit you have several options:

  • return data that was submitted with response and use MVCs "Model" to fill in the values
  • save data before submit somewhere (local storage, session, whatever)
  • do not do a full submit, but use ajax to query the API and display results
Sign up to request clarification or add additional context in comments.

2 Comments

I have made default unchecked But after checking it still it is maintaing its state and after postback, its remains unchecked.
@user3615920 I've edited my answer, please add controller code as well

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.