0
Answer

how to submit data using knockout.. for form

RAGHUNATH

RAGHUNATH

10y
1.1k
1
how to submit data using knockout..
and  i have below form like this..
 
 
 
<div id="div1">
<table align="center">
<tr>
<td>
Employee Id:
</td>
<td>
<input data-bind="value:EmpId" type="text" id="txtempid"/>
</td>
</tr>
<tr>
<td>
Name:
</td>
<td><input data-bind="value:EmpName" type="text" id="txtempname"/>
</td>
</tr>
<tr>
<td>
Designation:
</td>
<td><input data-bind="value:Designation" type="text" id="txtdesignation"/>
</td>
</tr>
<tr>
<td>
Department Name:
</td>
<td> <select id="CategoryType" style="width: 250px; height: 25px; margin-top: 10px;" data-bind="optionsText:'deptname', value:deptid">
</select>
</td>
</tr>
<tr>
<td align="right" colspan="2">
<input type="submit" value="Save" id="btnSave" name="btnSave" />
&nbsp
<input type="submit" value="Cancel" id="btnCancel" name="btnCancel" />
</td>
</tr>
</table>
</div>
   and i tried like below using knockout  but getting  an error..
 
 
<script type="text/javascript">
$('#btnSave').live("click", function (e) {
var viewModel = {
this.EmpId: ko.observable(""),
this.EmpName: ko.observable(""),
this.Designation: ko.observable(""),
this.deptid:ko.observable("")
};
ko.applyBindings(viewmodel);
$.ajax({
url: '/Home/Save/',
async: true,
cache: false,
type: 'post',
data: ko.toJSON(viewmodel),
contentType: 'application/json',
success: function (result) {
$("lblResult").val("Recorded inserted Sucessfully");
$("txtempid").text("");
$("txtdeptid").text("");
$("txtempname").text("");
$("txtdesignation").text("");
}
});
});
</script>
  can any one suggest answer please   ........