I found answers to similar questions in many places but it didn't work with me even by copy/paste the code!
I am developing an MVC/C# application and I have a I have a bool property like the following:
public bool IsMarried { get; set; }
On the view side, I have the following code to represent the property:
<label class="radio-inline">
@Html.RadioButtonFor(model => model.IsMarried , true)Yes
</label>
<label class="radio-inline">
@Html.RadioButtonFor(model => model.IsMarried , false)No
</label>
My problem is whwnever I submit the form, I get all of the rest of the normal fields (text) except the boolean property is always true
As I mentioned, there are many solutions I found such as this one but I don't know why it didn't work for me.
Added by author:
I wanted to add to this question to make everything visible. In addition to the code I am showing above, I am using Ajax
to submit the form.
This is the Ajax code:
function SaveWebFormToDatabase() {
var formData = new FormData();
//Append the other textboxes with the form data
formData.append("LastName", $("#LastName").val());
formData.append("FirstName", $("#FirstName").val());
formData.append("IsMarried", $("#IsMarried").val());
$.ajax({
type: "POST",
url: "../User/SaveFirstWebForm",
data: formData,
processData: false,
contentType: false,
success: function (data) {
$('#loading_div').hide();
},
error: function (exception) {
console.log(exception);
}
});
}
In the Controller side, this is the method that receives the call:
[HttpPost]
public JsonResult SaveFirstWebForm(WebApplicationFirstPhase model)
{
string Nme = model.FirstName + model.LastName;
bool ArmedFBit = model.IsMarried;//this is always true!
return Json("");
}