【发布时间】:2018-01-14 13:49:17
【问题描述】:
我正在使用Jquery 调用webService.asmx,在该服务中我正在检索usercontrolcontrol 的值以将它们保存在数据库中,但用户控件抛出了NullReferenceException
这里是Ajaxcall
function SaveEdit()
{
$.ajax({
type: "POST",
url: "Services/RatiosSettingsService.asmx/UpdateRatios",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (result) { }
});
}
这是WebServicecode
[WebMethod]
public void UpdateRatios()
{
using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["Crs2"].ConnectionString))
{
ADO ado = new ADO();
List<SqlParameter> parameters = new List<SqlParameter>();
ucOtherRatios2 obj = new ucOtherRatios2();
Dictionary<string, int> hs = obj.GetHsChks();
foreach (KeyValuePair<string, int> item in hs)
{
SqlParameter para = new SqlParameter(item.Key, item.Value);
parameters.Add(para);
}
con.Open();
ado.CUDSp("UpdateRatios", "spUpdateClientRatios",parameters,con);
con.Close();
}
}
这是在检索控件值的 usercontrol 方法中发生异常的地方
public Dictionary<string, int> GetHsChks()
{
Dictionary<string, int> chks = new Dictionary<string, int>();
chks.Add("@siAnalysisOtherRatiosHistorical1", Convert.ToInt32(chkOthWcHs.Checked));
chks.Add("@siAnalysisOtherRatiosHistorical2", Convert.ToInt32(chkOthWiHs.Checked));
chks.Add("@siAnalysisOtherRatiosHistorical3", Convert.ToInt32(chkOthTlgHs.Checked));
chks.Add("@siAnalysisOtherRatiosHistorical4", Convert.ToInt32(chkOthEiHs.Checked));
chks.Add("@siAnalysisOtherRatiosHistorical5", Convert.ToInt32(chkOthEcHs.Checked));
chks.Add("@siAnalysisOtherRatiosHistorical6", Convert.ToInt32(chkOthEicHs.Checked));
chks.Add("@siAnalysisOtherRatiosHistorical7", Convert.ToInt32(chkOthEsHs.Checked));
chks.Add("@siAnalysisOtherRatiosHistorical8", Convert.ToInt32(chkOthEtHs.Checked));
return chks;
}
它说复选框为空
【问题讨论】:
标签: c# jquery asp.net web-services