【发布时间】:2016-04-13 17:54:17
【问题描述】:
我有一个表单,我想使用带有 WCF 的 AJAX 提交,但问题是我的 Model("Client") 没有被填充。 当我提交表单时,它会到达服务但“客户”的所有字段都是空的。 我在这里错过了什么?
$("#myForm").on("submit", function (e) {
var Type = "POST";
var Url = "Service.svc/GetUser";
var Data = JSON.stringify($(this).serializeArray());
var ContentType = "application/json; charset=utf-8";
$.ajax({
type: Type, //GET or POST or PUT or DELETE verb
url: Url, // Location of the service
data: Data, //Data sent to server
contentType: ContentType, // content type sent to server
processdata: true,
success: function (result) {
$("#myForm").remove();
},
error: function (result) {
alert(result);
}
});
});
IService:
[ServiceContract]
public interface IService
{
[OperationContract]
[WebInvoke(Method = "POST")]
void GetUser(Client client);
}
[DataContract]
public class Client
{
[DataMember(Name = "Name")]
public string Name { get; set; }
[DataMember(Name = "Phone")]
public string Phone { get; set; }
[DataMember(Name = "Email")]
public string Email { get; set; }
[DataMember(Name = "Message")]
public string Message { get; set; }
}
Service.cs:
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class Service : IService
{
public void GetUser(Client client) { }
}
【问题讨论】: