[英]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.