试图在stringify formatv中传递json数据

时间:2017-12-11 10:37:33

标签: javascript c# jquery json ajax

我正在尝试通过Ajax传递stringify格式的JSON数据。贝洛是ajax部分

$.ajax({
    type: "POST",
    url: "TDC.aspx/SaveFrmDetails",
    data: '{user: "' + JSON.stringify(user) + '",byteData: "' + byteData + '", imageName: "' + fileName + '", contentType: "' + contentType + '" }',
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function (response) {
        alert("User has been added successfully.");
        window.location.reload();
    }
});

在服务器端这样收到 要保留的用户的属性

public class User
{
    public decimal PRODUCT_ID { get; set; }
    public string TDC_NO { get; set; }
    public decimal REVISION { get; set; }
    public DateTime REVISION_DATE { get; set; }
    public string P_GROUP { get; set; }
    public string PROD_DESC { get; set; }
    public string N_I_PRD_STD { get; set; }
    public string APPLN { get; set; }
    public string FRM_SUPP { get; set; }
    public DateTime CREATED_DATE { get; set; }
    public string CREATED_BY { get; set; }
}

网络方法

[WebMethod]    
    public static void SaveFrmDetails(User user, string byteData, string imageName, string contentType)
    {
        byte[] bytes = Convert.FromBase64String(byteData);
        string connectionString = ConfigurationManager.ConnectionStrings["connw"].ConnectionString;
 using (OracleConnection con = new OracleConnection(connectionString))
        {
            using (OracleCommand cmd = new OracleCommand("INSERT INTO TDC_PRODUCT1(PRODUCT_ID,TDC_NO, REVISION,REVISION_DATE,P_GROUP,PROD_DESC,N_I_PRD_STD,APPLN,FRM_SUPP,CREATED_DATE,CREATED_BY,NAME,CONTENTTYPE,DATA ) VALUES (:PRODUCT_ID,:TDC_NO,:REVISION,:REVISION_DATE,:P_GROUP,:PROD_DESC,:N_I_PRD_STD,:APPLN,:FRM_SUPP,:CREATED_DATE,:Created_By,:NAME,:CONTENTTYPE,:DATA)", con))
            {                
                cmd.CommandType = CommandType.Text;
                cmd.Parameters.AddWithValue(":PRODUCT_ID", user.PRODUCT_ID);
                cmd.Parameters.AddWithValue(":TDC_NO", user.TDC_NO);
                cmd.Parameters.AddWithValue(":REVISION", user.REVISION);
                cmd.Parameters.AddWithValue(":REVISION_DATE", user.REVISION_DATE);
                cmd.Parameters.AddWithValue(":P_GROUP", user.P_GROUP);
                cmd.Parameters.AddWithValue(":PROD_DESC", user.PROD_DESC);
                cmd.Parameters.AddWithValue(":N_I_PRD_STD", user.N_I_PRD_STD);
                cmd.Parameters.AddWithValue(":APPLN", user.APPLN);
                cmd.Parameters.AddWithValue(":FRM_SUPP", user.FRM_SUPP);
                cmd.Parameters.AddWithValue(":CREATED_DATE", user.CREATED_DATE);
                cmd.Parameters.AddWithValue(":CREATED_BY", user.CREATED_BY);
                cmd.Parameters.AddWithValue(":NAME", imageName);
                cmd.Parameters.AddWithValue(":CONTENTTYPE", contentType);
                cmd.Parameters.AddWithValue(":DATA", bytes);    
cmd.Connection = con;
                con.Open();
                cmd.ExecuteNonQuery();
                con.Close();
            }
        }
    }          

上述风格是否正确,或者需要进行任何修改。

0 个答案:

没有答案