I have a form with a field and a checkbox in an Ajax Form on a Modal Popup, When the user enters the data in the textbox and presses submit the values are posted and the Modal is closed. However if the user enters a value in the textbox and then checks the the checkbox the form will submit and the view will return to the modal on this time if the checkbox is checked I need to leave the form so that the user can submit another entry. The issue is that the textbox maintains its state, which is what I want and so does the Checkbox, but, the Underlying value of the checkbox switches back to false even though the checkbox is still checked...
A little stumped.
@using (Ajax.BeginForm("SaveValues", "ControllerName", new AjaxOptions()
{ HttpMethod = "Post",
OnComplete = "ChkForCheckBox();"
}))
{
@Html.TextBoxFor(x => x.DDate)
@Html.CheckBoxFor(x => x.Dupe)
<button type="submit" >Save</button>
}
and in the Controller.
public void SaveValues( string DDate, bool Dupe)
{
var rslt = repo.Post(DDate);
}
The JS.
function ChkForCheckBox(){
var rslt = $('#Dupe').prop('checked');
if(!rslt){
//Close Modal
}
}
However after the Ajax Post the CheckBox is still checked but the JS Script Check shows false? If I comment out the CloseModal and look through the code the Value is set to False? but if I post again it comes through as true? Verifying the ChkForCheckBox() again and it shows false.....
I'm missing something.
Aucun commentaire:
Enregistrer un commentaire