question

Shri-6058 avatar image
0 Votes"
Shri-6058 asked Bruce-SqlWork edited

@Html.RadioButtonFor click event not firing(change event works)

There are two problems currently I am stuck and appreciate any help on fixing I’m doing wrong :

(1) Very 1st time when I click the second radio button (value 2) and select the checkbox, it forces back to 1st checkbox and does no selection or no update to database. However if I try for the 2nd time onwards, all checkboxes and radio buttons maintain accurately.
(2) Radio button change event is working perfectly fine (show or hide div box). However I also want to enable click event for the radio button because, I want to perform “Reset checkbox values” when 1st radio button is selected back. The event is firing alternate scenarios. Example: if checkbox has values with 2nd radio button selected and then click 1st radio, it does not fires, if no checkbox selected and it fires to first radio button. I want to postback radio button selection on every click/change radio button event to controller. What is that I am doing wrong?
193698-untitled.jpg


193722-code-issue-description.txt


dotnet-csharpdotnet-aspnet-core-generaldotnet-runtimedotnet-aspnet-core-mvcdotnet-aspnet-mvc
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @Shri-6058,
(1) The first question is whether it happens every time, or only once?
(2)

@Html.RadioButtonFor click event not firing

I don't see the RadioButton click event in your code, the code doesn't work is there any error message?
You can refer to the code below:

  $("input[name=SelectedAttestation]").click(function () {
             $('input[type=checkbox]').prop('checked', false);
         });

Best regards,
Lan Huang

0 Votes 0 ·

I'm guessing the issue is related to your previous post where it is clear that you do not understand model state and HTML helpers. As explained in your other thread, the HTML helpers will read the model state passed to the action and will not see any changes to the model made programmatically after model binding. A workaround is to clear the model state then assing the new property values or create a new model and pass the new model to the view.

A far better solution is to take the time to learn fundamental MVC features rather than hacking a solution.

0 Votes 0 ·

1 Answer

Bruce-SqlWork avatar image
0 Votes"
Bruce-SqlWork answered Bruce-SqlWork edited

your javascript only does an Ajax call to the calculate action on document load. also the calculate action doesn't do anything. you probably wanted the Ajax call inside the change handler. but then the server does nothing with it anyway.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.