I work on asp.net MVC app . I face issue checkbox value not detected changing value from true to false or reverse .
meaning if I change checkbox Value from Yes to No OR No to Yes nothing detected according to speakstuff property model .
Exactly I need when checkbox check for yes then true and if check box for No will be false .
html script represent yes or No check box
@Html.Label("Did You Meet/Speak to Staff", htmlAttributes: new { @class = "control-label col-md-5" })
Yes
No
And below is jQuery to allow only selection with yes or no
model that represent property SpeakStuff
public class ResignationRequester
{
[Display(Name = "Employee No : ")]
[Required]
public int EmpID { get; set; }
[Display(Name = "Request No")]
public int RequestNo { get; set; }
public bool SpeakStuff { get; set; }
}
and When click approve button and check speakstuff property it still not changed
using (Html.BeginForm("ApprovalIndex", "Resignation", new { id = Model.RequestNo }, FormMethod.Post, htmlAttributes: new { @style = "display:inline;" }))
{
Approve
}
when debug model ResignationRequester speakstuff property it still true on all cases and if I change check box selection it still without change .
//post action method type
public async Task ApprovalIndex(ResignationRequester REQ)
{
}
So How to solve this issue ?
Tahir AnsariPosted Oct 16, 2023, 7:16 AM
With this change, the
ResignationRequester.SpeakStuffproperty will correctly represent the checkbox state astruewhen the checkbox is checked andfalsewhen it's unchecked.Tahir AnsariPosted Oct 16, 2023, 7:11 AM
With this script, when the user selects "Yes" or "No," the
SpeakStuffinput's value will be updated accordingly. This will ensure that when the form is submitted, the value of theSpeakStuffproperty in your model will betrueorfalsebased on the user's selection.