1

I have a few checkboxes values of which are posted to action, and when action calls the view again the checkboxes are checked according to their previous state:

<div class="D2">@Html.CheckBox("int", false, new { id = "int" })</div>
<div class="D2">@Html.CheckBox("ext", false, new { id = "ext" })</div>
<div class="D2">@Html.CheckBox("none", false, new { style = "visibility:hidden", id = "none" }
</div>

Action:

public ActionResult Images(bool? int, bool? ext, bool? none)
return View();

But I want the third theckbox ALWAYS to be unchecked, while the other ones should keep the settings. How can I achieve that please?

1
  • So you are setting the checked state explicitly to false and it still appears checked!? Commented Nov 4, 2011 at 23:32

2 Answers 2

1

The Html helper methods ALWAYS get the value from ModelState if they can.
To ensure the third checkbox will be unchecked, you should clear the ModelState value in your controller:

public ActionResult Images(bool? int, bool? ext, bool? none) {
    ModelState.Remove("none");
    return View();
}

For more info, see ModelState.Remove.

Sign up to request clarification or add additional context in comments.

Comments

0

If you want it to always be unchecked, why even send it into the method, simply use a value of false in your ActionResult. It doesn't have to be present in the parameter list. Am I not following something here?

Comments

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.