0
In a jquery function, I get a date in my View. It turns out that the date is coming like this:
/Date(1402369200000)/
I know I need to do a cast or something, but I don’t know how to do it. Can someone give me a hand? My controller:
[HttpPost]
public JsonResult MontaAgendamento(Agendamentos _agendamento)
{
V99_WEBEntities db = new V99_WEBEntities();
var agendamento = (
from pdv in db.T_PDV
from tarefa in db.T_TarefaParceiro.Where(trf => trf.CNPJ == pdv.CNPJ).DefaultIfEmpty()
from parceiro in db.T_OsParceiro.Where(prf => prf.IDTarefaParceiro == tarefa.IDTarefaParceiro)
from acao in db.T_Acao.Where(ac => ac.IDAcao == tarefa.IDAcao).DefaultIfEmpty()
from proxima in db.T_ProximaAcao.Where(pxm => pxm.IDAcao == acao.IDAcao).DefaultIfEmpty()
from info in db.T_InfoClientePdv.Where(inf => inf.CNPJ == pdv.CNPJ).DefaultIfEmpty()
from cliente in db.T_Cliente.Where(clie => clie.IDCliente == info.IDCliente).DefaultIfEmpty()
where pdv.CNPJ == _agendamento.Cnpj
orderby parceiro.DataVisita descending
select new
{
pdv.CNPJ,
pdv.DataCadastro,
cliente.RazaoSocial,
acao.Acao,
proxima.ProximaAcao,
parceiro.IDOsParceiro,
parceiro.NumOs,
parceiro.DataVisita,
parceiro.DataAgendamento,
parceiro.Tecnico
}).ToList().FirstOrDefault();
return Json(new { agendamento }, JsonRequestBehavior.AllowGet);
}
My jquery:
function MontaAgendamento() {
var str = "";
var resultado = jQuery.parseJSON('{ "Cnpj": "' + $("#txtCNPJ").val() + '" , "Os": "' + $("#txtOS").val() + '" , "Acao": "' + $("#txtAcao").val()
+ '" , "ProximaAcao": "' + $("#txtProxAcao").val() + '" , "DataCadastro": "' + $("#txtDataCadastro").val() + '" }');
var _agenda = $('#txtCNPJ').val() + $("#txtOS").val();
$.ajax({
url: '/GerenciarPDV/MontaAgendamento',
dataType: "json",
contentType: "application/json; charset=utf-8",
type: "POST",
data: JSON.stringify({ _agendamento: resultado}),
success: function (data) {
alert(data.agendamento.Acao);
str += '<div id="FiltroPesquisa">';
str += '<div id="painelAcao">';
str += '<table style="width: 100%;border-top: 1px solid black;">';
str += '<tr>';
str += '<td></td>';
str += '</tr>';
str += '</table>';
str += '<table style="width: 100%;">';
str += '<tr>';
str += '<td class="Formatlabel">';
str += '<label id="lblProxAcao">Ação</label></td>';
str += '<td class="auto-style9">';
str += '<input id="txtAcao" type="text" readonly="true" value="' + data.agendamento.Acao + '" /></td>';
str += '<td class="Formatlabel">Próxima Ação</td>';
str += '<td>';
str += '<input id="txtProxAcao" type="text" readonly="true" value="' + data.agendamento.ProximaAcao + '" /></td>';
str += '</tr>';
str += '<tr>';
str += '<td class="Formatlabel">';
str += '<label id="lblDTCadastro">Data Cadastro</label></td>';
str += '<td class="auto-style24">';
str += '<input id="txtDataCadastro" type="text" readonly="true" value="' + data.agendamento.DataCadastro + '" /></td>';
str += '<td class="Formatlabel">';
str += '<label id="lblIDV99">ID V99:</label></td>';
str += '<td class="auto-style5">';
str += '<input id="txtIDV99" type="text" readonly="true" value="' + data.agendamento.IDOsParceiro + '"/></td>';
str += '</tr>';
str += '<tr>';
str += '<td class="Formatlabel">';
str += '<label id="lblDTAgendamento">Data Agendamento</label></td>';
str += '<td class="auto-style9">';
str += '<input id="txtDataAgenda" type="text" readonly="true" value="' + data.agendamento.DataAgendamento + '"/></td>';
str += '<td class="Formatlabel">';
str += '<label id="lblTipoVisita">Tipo de Visita</label></td>';
str += '<td>';
str += '<input id="txtTipoVisita" type="text" readonly="true" value="' + + '"/></td>';
str += '</tr>';
str += '<tr>';
str += '<td class="Formatlabel" style="width: 141px; font-weight: 700;">Data Visita</td>';
str += '<td class="auto-style9">';
str += '<input id="txtDataVisita" type="text" readonly="true" value="' + data.agendamento.DataVisita + '"/></td>';
str += '<td style="width: 110px;">';
str += '</td>';
str += '<td>';
str += ' </td>';
str += '</tr>';
str += '</table>';
str += '</div>';
.................................
$('#filtro').html(str);
str = "";
},
error: function (error) {
}
})
}
I couldn’t convert because of the /Date and / at the end. How do I do for a new date (myfield) without those characters that invalidate the construction of the date
– pnet
In this case, it is common to replace unwanted information. See more details here: http://stackoverflow.com/questions/1016847/converting-net-datetime-to-json
– anmaia
I strongly advise you to use Moment.js. If you are working with Javascript dates and need to format them, this is the best lib I used.
– anmaia