In textbox Ticket
, in event onChange()
I call AJAX below:
$('#Ticket').on('change', function () {
var tkt = this.value;
$.ajax({
url: '@Url.Action("VerificaTicket", "Oc")',
data: { 'tkt': tkt },
type: "post",
cache: false
});
});
Calling the action below:
[HttpPost]
public ActionResult VerificaTicket(int tkt)
{
Oc oc = db.Ocs.Find(tkt);
if (oc != null)
{
ViewBag.IdStatus = new SelectList(db.Status, "IdStatus", "Descricao", oc.IdStatus);
ViewBag.IdEmpresa = new SelectList(db.Empresas, "IdEmpresa", "Apelido");
ViewBag.IdFornecedor = new SelectList(db.Fornecedors, "IdFornecedor", "Apelido");
ViewBag.IdFaturamento = new SelectList(db.Faturamentoes, "IdFaturamento", "Apelido");
ViewBag.IdEntrega = new SelectList(db.Entregas, "IdEntrega", "Apelido");
ViewBag.IdProdutos = new SelectList(db.Produtos, "IdProdutos", "Descricao");
ViewBag.TicketExiste = "Sim";
return RedirectToAction("Create", "Oc");
}
return this.View();
}
In view Create
I'll check:
@if (@ViewBag.TicketExiste == "Sim") {
<script type="text/javascript">
alert("Ticket já existe!");
</script>
}
Following the breakpoint, it even happens in the if
of alert
, but does not execute, I do not know what happens.