Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/295.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Ajax将数据发布到服务器端-错误500内部服务器错误_C#_Jquery_Asp.net_Ajax - Fatal编程技术网

C# Ajax将数据发布到服务器端-错误500内部服务器错误

C# Ajax将数据发布到服务器端-错误500内部服务器错误,c#,jquery,asp.net,ajax,C#,Jquery,Asp.net,Ajax,我有一个文本框列表,我通过jquery获得,我试图通过一个模型将它们发送到服务器端 我在服务器端设置了一个断点(webmethod),但它不会命中 帮忙 这是页面中的代码: function CreareCont() { var model = {}; model.Nume = txtNume.val(); model.Prenume = txtPrenume.val(); model.CNPsauCUI = txtCNPsauCU

我有一个文本框列表,我通过jquery获得,我试图通过一个模型将它们发送到服务器端

我在服务器端设置了一个断点(webmethod),但它不会命中

帮忙

这是页面中的代码:

function CreareCont() {
        var model = {};
        model.Nume = txtNume.val();
        model.Prenume = txtPrenume.val();
        model.CNPsauCUI = txtCNPsauCUI.val();
        model.Strada = txtStrada.val();
        model.Numar = txtNumar.val();
        model.Etaj = txtEmail.val();
        model.Apartament = txtApartament.val();
        model.Oras = txtOras.val();
        model.SectorSauJudet = txtSectorSauJudet.val();
        model.Telefon = txtTelefon.val();
        model.Email = txtEmail.val();
        model.Parola = txtParola.val();
        $.ajax({
            type: "POST", url: webservicePageUrl + "/CreareCont",
            data: JSON.stringify(model),
            contentType: "application/json; charset=utf-8", dataType: "json",
            success: OnSuccessCall1, error: OnErrorCall1
        });
    };
    function OnSuccessCall1(response) { alert(response.d); };
    function OnErrorCall1(response) { alert(response.status + " " + response.statusText); debugger; };
正如我从控制台中看到的,模型send似乎还可以,它的值是:

{"Nume":"asd","Prenume":"asd","CNPsauCUI":"asd","Strada":"asd","Numar":"asd","Etaj":"asd","Apartament":"asd","Oras":"asd","SectorSauJudet":"asd","Telefon":"asd","Email":"asd","Parola":"asdasd123"}
这是Web服务代码:

[WebMethod]
public void CreareCont(Inregistrare user)
{
    string hash = helper.GetSHA1HashData("123");

}
该模型为C级:


使用fiddler后,我收到以下错误:{“消息”:“无效的web服务调用,缺少参数值:\u0027user\u0027.”,“StackTrace”:“at System.web.Script.Services.WebServiceMethodData.CallMethod(对象目标,IDictionary`2参数)\r\n at System.web.Script.Services.WebServiceMethodData.CallMethodFromRawParams(对象目标,IDictionary的2个参数)\r\n位于System.Web.Script.Services.RestHandler.InvokeMethod(HttpContext上下文,WebServiceMethodData,IDictionary的2个rawParams)\r\n位于System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext,WebServiceMethodData)”,“ExceptionType”:“System.invalidoOperationException”}

您的webmethod需要是静态的,除非它位于asmx中

public static void CreareCont(Inregistrare user)
json数据需要与webmethod的参数同名

data: '{"user":'+ JSON.stringify(model)+ '}'
在类属性中包括
Public
,比如
publicstringnume{get;set;}
,需要在类对象中反序列化json

试试这个代码

js

cs


尝试使
CreateCont
static
。您可能还应该在global.asax中捕获并记录应用程序错误,以帮助您进行调试。您确定生成的url正确吗?使用一些客户端开发工具,如firebugconfirm@AshleyJohn是的,url还可以,我检查过了…它是“/Code/WebService/EBusinessWS.asmx/CreareCont”“我的Web服务在这两个文件夹中…没关系…@JasonP我如何捕获并记录错误?请尝试在ajax设置中命名输入参数。类似于“数据:{user:JSON.stringify(model)}”
data: '{"user":'+ JSON.stringify(model)+ '}'
function CreareCont() {
        var model = {};
        model.Nume = txtNume.val();
        model.Prenume = txtPrenume.val();
        model.CNPsauCUI = txtCNPsauCUI.val();
        model.Strada = txtStrada.val();
        model.Numar = txtNumar.val();
        model.Etaj = txtEmail.val();
        model.Apartament = txtApartament.val();
        model.Oras = txtOras.val();
        model.SectorSauJudet = txtSectorSauJudet.val();
        model.Telefon = txtTelefon.val();
        model.Email = txtEmail.val();
        model.Parola = txtParola.val();
        $.ajax({
            type: "POST", url: webservicePageUrl + "/CreareCont",
            data: '{"user":'+ JSON.stringify(model)+ '}',
            contentType: "application/json; charset=utf-8", dataType: "json",
            success: OnSuccessCall1, error: OnErrorCall1
        });
    };
[WebMethod]
public static void CreareCont(Inregistrare user)
{
    string hash = helper.GetSHA1HashData("123");

}

public class Inregistrare
{
    public string Nume { get; set; }
    public string Prenume { get; set; }
    public string CNPsauCUI { get; set; }
    public string Strada { get; set; }
    public string Numar { get; set; }
    public string Etaj { get; set; }
    public string Apartament { get; set; }
    public string Oras { get; set; }
    public string SectorSauJudet { get; set; }
    public string Telefon { get; set; }
    public string Email { get; set; }
    public string Parola { get; set; }
}