[英]object properties is null after ajax callback in asp.net webmethod
this is not asp.net mvc, this is asp.net webforms 这不是asp.net mvc,这是asp.net webforms
I am trying to send object literal like this 我正在尝试像这样发送对象文字
templateProperties = {}
and my ajax call like this 和我的ajax电话是这样的
$.ajax({
beforeSend:updateTemplateProperties,
type: "POST",
url: templatePropertiesUpdateUrl,
contentType: 'application/json; charset=utf-8',
dataType: 'json',
data: JSON.stringify({ "templateProperties": templateProperties }),
}).done(function (data) {
log(data.d);
});
I am calling function before sending: 我在发送前调用函数:
updateTemplateProperties = function () {
templateProperties.NameFont = "qwq";
templateProperties.NameBold = true;
templateProperties.NameItalic = false;
templateProperties.NameFontColor = "#FFF";
templateProperties.NamePositionX = 52;
templateProperties.NamePositionY = 896;
templateProperties.NameSize = 23;
templateProperties.DateFont = "ssda";
templateProperties.DateBold = false;
templateProperties.DateItalic = true;
templateProperties.DateFontColor = "#EEE";
templateProperties.DatePositionX = 47;
templateProperties.DatePositionY = 236;
templateProperties.DateSize = 12;
}
adn My webmethod is like that 我的网络方法就是这样
[WebMethod]
public static string UpdateTemplateProperties(TemplateProperties templateProperties)
{
var serializer = new JavaScriptSerializer();
return serializer.Serialize(templateProperties);
}
and this is my TemplateProperties class 这是我的TemplateProperties类
[Serializable]
public class TemplateProperties
{
public string NameFont { get; set; }
public string NameBold { get; set; }
public string NameItalic { get; set; }
public string NameFontColor { get; set; }
public string NamePositionX { get; set; }
public string NamePositionY { get; set; }
public string NameSize { get; set; }
public string DateFont { get; set; }
public string DateBold { get; set; }
public string DateItalic { get; set; }
public string DateFontColor { get; set; }
public string DatePositionX { get; set; }
public string DatePositionY { get; set; }
public string DateSize { get; set; }
}
when checking templateProperties I found the entire object properties equal to null 当检查templateProperties时,我发现整个对象的属性等于null
{"NameFont":null,"NameBold":null,"NameItalic":null,"NameFontColor":null,"NamePositionX":null,"NamePositionY":null,"NameSize":null,"DateFont":null,"DateBold":null,"DateItalic":null,"DateFontColor":null,"DatePositionX":null,"DatePositionY":null,"DateSize":null}
I am not getting any error from this call, and I have tried everything I know but it is not working normally I pass the parameters individually to the webmethod one by one but this time they are too much to do so , So I want to send the whole object as one entity 我没有从此调用中收到任何错误,并且我已经尝试了所有我知道的内容,但是它无法正常工作,我将参数逐个逐个传递给了web方法,但是这次它们实在太多了,所以我想发送整个对象作为一个实体
由于某种原因,调用了beforeSend
回调函数updateTemplateProperties
,但是在发送数据之前未正确初始化templateProperties
,我只是在开始ajax调用之前调用了updateTemplateProperties
函数,它现在可以正常工作,但是我真的不知道为什么会这样不能这样工作
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.