Khaled Musaied
Khaled Musaied

Reputation: 2493

The value '[object HTMLInputElement]' is not valid

I am getting the following error when submitting the form:

The value '[object HTMLInputElement]' is not valid for MaritalStatus

this is the Model:

public class CompanionsModel
{
        public char Gender { get; set; }
        public int MaritalStatus { get; set; }
}

this is the view:

<input type="hidden" id="MaritalStatus" name="MaritalStatus" data-bind="value: MaritalStatus" value="@Model.MaritalStatus" />
    @Html.HiddenFor(m => m.Gender, new {data_bind="value: StudentGender" })

this is the knockoutsjs code:

 function CompanionController() {
            var self = this;
            var GenderValue = $("[name=Gender]").val();
            var MaritalStatusValue = $("#MaritalStatus").val();

            self.StudentGender = ko.observable(GenderValue); 

            self.StudentMaritalStatus = ko.observable(MaritalStatusValue);
}

Upvotes: 1

Views: 2657

Answers (1)

Khaled Musaied
Khaled Musaied

Reputation: 2493

The error was because the invalid Knockouts data-binding in the 'MaritalStatus' checkbox

the correct binding is ' StudentMaritalStatus' NOT 'MaritalStatus'

<input type="hidden" id="MaritalStatus" name="MaritalStatus" data-bind="value: StudentMaritalStatus" value="@Model.MaritalStatus" />

Upvotes: 5

Related Questions