我有webmethods作爲「插入」和「更新」,我有我的記錄的C#類爲「DataParam」...我通過使用AJAX調用它。對於更新方法,沒有問題,我已通過Ajax調用發送Class並進行更新,但是對於Insert,我有錯誤500. 我無法克服它。從Ajax發送C#類,錯誤500
這裏是我的類:
public class DataParam
{
public string ATC1 { get; set; }
public string ATC2 { get; set; }
public string ATC3 { get; set; }
public string ATC4 { get; set; }
public string CurentlyProjectMark { get; set; }
public int Dosage { get; set; }
public string Dosage_Title { get; set; }
public string FirstMark { get; set; }
public int Form { get; set; }
public string Form_Title { get; set; }
public long Id { get; set; }
public Guid Key { get; set; }
public string LicensedTradeMark { get; set; }
public long Molecule { get; set; }
public string Molecule_Title { get; set; }
public string ProductName { get; set; }
public int ProjectCode { get; set; }
public string ProjectCode_Title { get; set; }
public DateTime RD_DataProtectionEndDate { get; set; }
public string RD_Description { get; set; }
public int RD_Document_Author { get; set; }
public DateTime RD_Document_CheckDate { get; set; }
public string RD_Document_CheckDescription { get; set; }
public DateTime RD_Document_ComingDate { get; set; }
public string RD_Document_ComingDescription { get; set; }
public int RD_Document_Controller { get; set; }
public DateTime RD_Document_DoneDate { get; set; }
public string RD_Document_DoneDescription { get; set; }
public DateTime RD_Document_RealesedDate { get; set; }
public string RD_Document_RealesedDescription { get; set; }
public int RD_Document_Status { get; set; }
public DateTime RD_Document_TargetDate { get; set; }
public string RD_Document_TargetDescription { get; set; }
public int RD_ProjectedFirm { get; set; }
public string RD_ProjectedName { get; set; }
public int RD_Responsible { get; set; }
public int RD_Status { get; set; }
public string Title { get; set; }
public string TradeMark { get; set; }
}
這裏是方法
[WebMethod(EnableSession = true)]
public static object Update(DataParam param = null)
{
try
{
CPI.RD.Product product = new CPI.RD.Product();
object objProduct = (CPI.RD.Product)product;
product = (CPI.RD.Product)CPI.RD.Helper.FillBussinesObject(param, ref objProduct);
CPI.RD.ProductManagement.Update(product);
return true;
}
catch (Exception ex)
{
return new { Result = "ERROR", Message = ex.Message };
}
}
[WebMethod(EnableSession = true)]
public static object Insert2(DataParam param = null)
{
try
{
CPI.RD.Product product = new CPI.RD.Product();
object objProduct = (CPI.RD.Product)product;
product = (CPI.RD.Product)CPI.RD.Helper.FillBussinesObject(param, ref objProduct);
CPI.RD.ProductManagement.Insert(product);
return true;
}
catch (Exception ex)
{
return new { Result = "ERROR", Message = ex.Message };
}
}
這裏是AJAX調用
var param = cpiGrid.getRecordForm(record);
// Check if it is new record
if ($(div).attr("data-new") == "true") {
url += "Insert2";
record = cpiGrid.getRecordForm(record);
data = JSON.stringify(record);
console.log("send to add: ", record, " data: ", data);
cpiGrid.getJSON(url, data, function() {
cpiGrid.listRecords();
$(".close-button").trigger("click");
});
}
詳細的錯誤信息:
{"Message":"Invalid web service call, missing value for parameter: \u0027param\u0027.","StackTrace":" at System.Web.Script.Services.WebServiceMethodData.CallMethod(Object target, IDictionary`2 parameters)\r\n at System.Web.Script.Services.WebServiceMethodData.CallMethodFromRawParams(Object target, IDictionary`2 parameters)\r\n at System.Web.Script.Services.RestHandler.InvokeMethod(HttpContext context, WebServiceMethodData methodData, IDictionary`2 rawParams)\r\n at System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext context, WebServiceMethodData methodData)","ExceptionType":"System.InvalidOperationException"}
什麼是實際錯誤? – SLaks 2012-08-15 14:13:51
什麼是具體的500錯誤? 500是服務器錯誤,因此請檢查服務器的事件日誌以查看異常情況。或者使用Fiddler或Firebug來查看客戶端的響應。 – 2012-08-15 14:14:02
我編輯關於錯誤消息的問題,我認爲它是關於類和變體類型和值。 – efirat 2012-08-15 14:21:04