[英]Internal Server Error(500) when adding a record to a table using Odata and Knockout Js in Asp.Net MVC
我正在尝试使用以下脚本使用Knockout Js和OData将记录添加到SQL表中。
淘汰赛
self.Grade = ko.observable();
self.selectedProduct = ko.observable();
self.add = function (grade) {
var payload = { ProductName: this.selectedProduct(), GradeName:this.Grade(), Locked:false };
$.ajax({
url: '/odata/Grades',
type: 'POST',
data: JSON.stringify(payload),
contentType: 'application/json',
dataType: 'json'
});
}
的HTML
<td >
<select data-bind="options: $root.productNames, optionsText: 'ProductName', optionsValue: 'ProductName', value: selectedProduct, optionsCaption: 'Product'">
</select></td>
<td>
<input type="text" id="txbInput" placeholder="Grade Name" data-bind="value: Grade"/> </td>
<td>
<input type="button", onclick="ClearFields();" class="btn btn-success" data-bind=" click: add, visible: !loading()", value="Add Grade"/></td>
</tr>
但是由于某些原因,当我单击“ Add Grade
按钮以添加记录时,它向我抛出异常,如下所示
Failed to load resource: the server responded with a status of 500 (Internal Server Error) http://localhost:57044/odata/Grades
请问原因和最佳解决方案。
弄清楚自己。 一个简单的错误是我没有插入值Id
列,并且它不能为NULL
因为它是键。 我将SQL表中Id
列的Identity specification
属性更改为Yes,它起作用了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.