Sergiu BRC
Sergiu BRC

Reputation: 17

How to get the id of the checked person from jQuery to ASP.NET Core 6 MVC controller?

I want to create a voting system in ASP.NET Core 6 MVC:

enter image description here

I have a jQuery script that verify is only one checkbox is checked of the class name. After I press the button, I want to display the selected options. The image and the name of candidate.

How can I get details from the database (using Entity Framework) for the selected option? I suppose that I need somehow to get the selected one in controller. I tried but I didn't have any success.

@section scripts {
<script type="text/javascript">
    $(document).ready(function () {
        $(".ceo").on("change", function () {
            if ($(".ceo:checked").length == 1) {
                $(".ceo").attr("disabled", "disabled");
                $(".ceo:checked").removeAttr("disabled");
            }
            else {
                $(".ceo").removeAttr("disabled");
            }
        });

        $(".productmanager").on("change", function () {
            if ($(".productmanager:checked").length == 1) {
                $(".productmanager").attr("disabled", "disabled");
                $(".productmanager:checked").removeAttr("disabled");
            }
            else {
                $(".productmanager").removeAttr("disabled");
            }
        });
     });
</script>

Upvotes: 0

Views: 131

Answers (0)

Related Questions