1

Basically what the title says:

This must happen without having a submit button. This is what I got, but have no idea how to go further:

View

<% using (Html.BeginForm("UpdateReleaseState", "Articles", new{reference=Model.Reference, CheckboxState=true})) {%>
                    <%=Html.CheckBox("CheckboxState", Model.DoNotCheckReleaseState)%> Do not check release state
</div>

Action

 [HttpPost]
 public ActionResult UpdateReleaseState(Guid reference, bool CheckboxState)
 {
     throw new NotImplemtedException();
 }

In my view I am trying to pass the value of the Checkbox, but dont know what to provide as parameter.Currently it is check=true

user1702369
  • 1,089
  • 2
  • 13
  • 31

2 Answers2

1

In your CheckBox method you have specified its name - CheckboxState. Therefore after the form is posted, request will contain part CheckboxState=true or CheckboxState=false. Now all you need to do is to specify the same name for the action parameter (case insensitive):

public ActionResult UpdateReleaseState(Guid reference, bool checkboxState)
Andrei
  • 55,890
  • 9
  • 87
  • 108
0

You need to change your signature to this:

public ActionResult UpdateReleaseState(Guid reference, bool CheckboxState)

MVC uses names to bind values. And one other note, casing is important, just because it's more readable the interpretable. But as discovered by Andrei, it's not relevant to it working.

Mike Perrenoud
  • 66,820
  • 29
  • 157
  • 232
  • About case - is it? As far as I know it is not. – Andrei Jun 13 '13 at 14:09
  • @Andrei, I remember having an issue with casing a while back. It could be that I modified something else along the way that fixed it too, but I guess since then I've always ensured that the casing is correct. In short, MVC uses `Reflection` to find the properties to bind to, and unless otherwise specified, it's case-sensitive. – Mike Perrenoud Jun 13 '13 at 14:12
  • I very much doubt that your issue was cause by casing. You can try it yourself with a basic example: send a post request with `ID` and receive it in action as `id`. Just tried that to be absolutely sure, everything worked as expected. This is not the say that you rule to about casing is a bad one - it is quite useful I think. – Andrei Jun 13 '13 at 14:47
  • @Andrei, fantastic discovery and proof, thanks! I learned something today. I've updated my answer, and +1 for too friend as your answer is just as correct. – Mike Perrenoud Jun 13 '13 at 15:50
  • Thank you for your answers, me too learned something.But still it doesn't seem to post, when checking it still does not got to the action.How to I pass the control value.Currently: <% using (Html.BeginForm("UpdateReleaseState", "Articles", new { reference = Model.Reference}))%> <%=Html.CheckBox("checkboxSapState", Model.DoNotCheckReleaseState)%> Do not check release state – user1702369 Jun 14 '13 at 06:45
  • @user1702369, and what's the action signature look like? – Mike Perrenoud Jun 14 '13 at 07:33
  • public ActionResult UpdateReleaseState(Guid reference, bool checkboxSapState) – user1702369 Jun 17 '13 at 10:01
  • @user, according to you the name of the check box is checkBoxState, not checkboxSapState. The parameter name must be the same as the control name. – Mike Perrenoud Jun 17 '13 at 10:25
  • Arggg all the typo's.Look at my initial question.I up dated how I'm calling it currently – user1702369 Jun 17 '13 at 10:27