Skip to content
Advertisement

Why is my on click event not working? (ASP.NET MVC)

I have a checkbox in my view, with an onclick event which sends the checkboxes ID to an action result in my controller (using Ajax). However, after running a breakpoint on the passed value within my controller, it seems as thou nothing is happening when i click on the checkbox? Why could this be?

My checkbox:

JavaScript

Jquery for sending the value to my ActionResult:

JavaScript

And finally my ActionResult within my “Items” controller:

JavaScript

What i am trying to do is pass the value of “Remember”, which if i am correct, would be either true or false depending on whether the checkbox is ticked or not.

Advertisement

Answer

Because you have bool Remember parameter, you need send Remember parameter, and your URL miss “/”, update your function as

JavaScript

If you don’t want to put Remember parameter in POST method, you can set default value in action controller as

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement