0
I have a code in JavaScript
who does a search in a database and fills in a input
with the patient’s name found:
$("#bCns").keypress(function (e) {
if (e.which == 13) {
var options = {};
options.url = "/Home/pegaPaciente";
options.type = "GET";
options.data = { "pCns": $("#bCns").val() };
options.dataType = "json";
options.success = function (data) {
$("#pnPaciente").css("display", "block");
$("#bNome").val(data.nome); //<<PREENCHE AQUI
};
$.ajax(options);
}
});
I want to know how to make one if
to, if there is no result, fill in $("#bNome").val("PACIENTE NAO ENCONTRADO");
In my Controller
I make the appointment at the bank so:
public JsonResult pegaPaciente(string pCns)
{
paciente oPaciente = modelOff.pacientes.SingleOrDefault(p => p.cns == pCns);
return Json(oPaciente, JsonRequestBehavior.AllowGet);
}
I’ve tried to:
if (!data){}
if (data == false){}
This depends on what the database returns if there is no patient found.
– Isac
I changed the question
– Italo Rodrigo