2
In the textbox Ticket
, at the 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 check it out:
@if (@ViewBag.TicketExiste == "Sim") {
<script type="text/javascript">
alert("Ticket já existe!");
</script>
}
accompanying the breakpoint, until it passes in the if
of alert
, but it doesn’t perform, I don’t know what happens.