I have a code in JavaScript
that searches a database and fills a input
with the name of the patient 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 a if
so, if it does not have any results, it fills $("#bNome").val("PACIENTE NAO ENCONTRADO");
In my Controller
I make the query in the bank like this:
public JsonResult pegaPaciente(string pCns)
{
paciente oPaciente = modelOff.pacientes.SingleOrDefault(p => p.cns == pCns);
return Json(oPaciente, JsonRequestBehavior.AllowGet);
}
I've tried:
if (!data){}
if (data == false){}