I am trying to send an object by means of a POST request, however I have some problems with one of the attributes of that object (datetime).
date = $("#dpkparam").val();
fecha = new Date(date.replace(/(\d{2})-(\d{2})-(\d{4})/, "$2/$1/$3"));
var perfil = {};
perfil.idperfil = 100;
perfil.nombre = "nuevoperfil";
perfil.LogFechacrea = fecha;
$.ajax({
type: 'POST',
url: pathservicehost + '/perfiles',
data: JSON.stringify(perfil),
dataType: 'JSON',
contentType: 'application/json; charset=utf-8',
success: function (data, textStatus, res) {
alert("Perfil Ok...");
},
error: function (e) {
alert('Perfil Falló... ');
}
});
The class that I try to save in the database is the following:
public class CPerfil : CGenerico<int>
{
[DataMember]
public int idperfil;
[DataMember]
public string nombre;
[DataMember]
public DateTime LogFechacrea;
}
public void save(CPerfil obj)
{
using (SEntidades.Entidades ctx = new SEntidades.Entidades())
{
perfil objPerfil = new perfil();
objPerfil.idperfil = obj.idperfil;
objPerfil.descripcion = obj.nombre;
objPerfil.log_fechacrea = DateTime.Now;
//objPerfil.log_fechacrea = obj.LogFechacrea; error
ctx.perfil.AddObject(objPerfil);
ctx.SaveChanges();
return 1;
}
}
The error is in the date ... and what I need to know is what is the way to send this attribute.
Thank you.