I'm new in mvc5
I want to display error message for if the customer mobile number filed that not available in database
I tried similarly with this it works well for first condition but with for else doesn't
$(document).ready(function () {
$('#customer_mobile').change(function () {
$.ajax({
url: '/Cases/History_Test?searchMobile=' + $('#customer_mobile').val(),
method: 'GET',
success: function (data) {
if('#customer_mobile' == true)
{
var Output = "<h4 align=center> History of Cases for</h4>";
Output += "<table>"
Output += "<tr>"
Output += "<th>" + " Case ID </th>";
Output += "<th>" + " Case Name </th>";
Output += "<th>" + " Customer Name </th>";
Output += "</tr>";
for (var i = 0; i < data.length; i++)
{
Output += "<tr>"
Output += "<td>" + " " + data[i].case_id + " </td>";
Output += "<td>" + data[i].case_name + " </td>";
Output += "<td>" + data[i].customer_name + " </td>";
Output += "</tr>"
}
Output += "</table>"
//alert(Output);
$('#partView').html(Output);
}
else{
$('#customer_mobile').change(function () {
$.ajax({
url: '/Cases/Check_Customer?searchMobile=' + $('#customer_mobile').val(),
method: 'GET',
success: function (data) {
alert("Error this customer not avalibale ")
}
});
});
}
}
});
});
});
and my controller
public ActionResult History_Test(string searchMobile)
{
var cases = from c in db.Case
select c;
if (!String.IsNullOrEmpty(searchMobile))
cases = cases.Where(c => c.Customer.customer_mobile.Contains(searchMobile));
else
cases = cases.Where(p => p.case_id == -1);
return Json(cases.Select(d => new { case_id = d.case_id, case_name = d.case_name, customer_mobile = d.customer_mobile, customer_name = d.Customer.customer_name }), JsonRequestBehavior.AllowGet);
}
public ActionResult Check_Customer(string CheckhMobile)
{
var cases = from c in db.Case
where c.customer_mobile==CheckhMobile
select c;
if (cases.Count() > 0)
return Json(new { exising = true }, JsonRequestBehavior.AllowGet);
else
return Json(new { exising = false }, JsonRequestBehavior.AllowGet);
}
Aucun commentaire:
Enregistrer un commentaire