gpt4 book ai didi

c# - 没有为类型定义无参数构造函数.. Ajax JQuery 调用时出错

转载 作者:太空宇宙 更新时间:2023-11-03 10:25:20 25 4
gpt4 key购买 nike

当我执行我的 Ajax JQuery 时出现以下错误:

enter image description here

下面是我使用的代码:
IPRRequest.cs类代码(.dll)

public static bool IsValidBarcodeTest(Guid? requestID, string barCode)
{
bool result = true;

Dictionary<string, object> input = new Dictionary<string, object>() {
{"@RequestID", requestID},
{"@BarcodeNo", barCode}
};
Data data = new Data();
DataTable dt = data.ExecuteQuery(CommandType.StoredProcedure, "Invoice.usp_tbl_Request_Select_CheckDuplicateBarcode_Test", input);
if (dt.Rows.Count > 0)
{
result = Helper.GetDBValue<int>(dt.Rows[0][0]) == 0;
}
return result;
}

.aspx.cs页面代码:

public abstract class Check
{
public abstract Guid? requestID { get; set; }
public abstract string barCode { get; set; }
}

[WebMethod]
[ScriptMethod]
public static bool CheckDuplicate(Check chk)
{
bool isExist = false;

isExist = IPRRequest.IsValidBarcodeTest(chk.requestID, chk.barCode);

return isExist;
}

Ajax JQuery 代码:

<script type="text/javascript">
$(document).ready(function () {
$("[id*=btnSave]").bind("click", function () {

var chk = {};
chk.requestID = $("[id*=TempGUID]").text();
alert(chk.requestID);
chk.barCode = $("[id*=txtBarcodeNumber]").val();
alert(chk.barCode);

$.ajax({
type: 'POST',
url: "IPRForm_EditCheck.aspx/CheckDuplicate",
data: '{chk: ' + JSON.stringify(chk) + '}',
contentType: 'application/json; charset=utf-8',
dataType: 'json',
success: function (data) {

var val = data.d;
alert(val);

if (val == true) {
alert("Barcode Number already exist in system database.");
}
else {
alert("Barcode Number does not exist");
}

},
error: function (data) {
alert(data.responseText);
},
});
return false;
});
});
</script>

存储过程

Select 
Case When count(1) > 0
Then 1 --Exist
Else 0 --Not Exist
End As Duplicate
From Invoice.tbl_Request(NOLOCK)
Where BarcodeNo = @BarcodeNo
And (@RequestID Is Null Or RequestID <> @RequestID)

请回复我的代码有什么问题。
请注意,我是 Ajax JQuery 和 Web 方法方面的新手
提前致谢。

最佳答案

.NET 需要创建一个类型为 Check 的对象作为参数传递给 WebMethod CheckDuplicate。它不能创建抽象类的对象。

如果将 class Check 更改为以下内容,它应该可以工作:

public class Check
{
//This constructor is needed, but .NET will create
//it automatically if no other constructors are defined
public Check() { }

private Guid? requestID;
private string barCode;

public Guid? RequestId
{
get { return requestID; }
set { requestID = value; }
}

public string BarCode
{
get { return barCode; }
set { barCode = value; }
}
}

关于c# - 没有为类型定义无参数构造函数.. Ajax JQuery 调用时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31783243/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com