使用ajax处理Bool函数

时间:2014-02-14 11:40:14

标签: jquery ajax linq boolean

我试图在truefalse bool结果的基础上对ajax成功函数做一些事情。

当我跨数据库检查电子邮件时 -

功能 -

 public bool RegisterEmail(string email) {
            var registeredemail = (from u in db.FunRegistereds
                                   where u.EmailAddress == email
                                   select u).ToList();
            if (registeredemail.Count() == 0 && registeredemail == null) {
                return false;
            }
            else {
                return true;
            }
        }

Ajax处理 -

$(function () {
    $('#exist-email').on('keyup', function () {
        var email = $('#exist-email').val();
        $.ajax({
            url: '/Account/RegisterEmail/?email=' + email,
            type: 'post',
            success: function (data) {
                if (!data) {
                    $('.avalibility-email').html("<h2>" + "'" + email + "'" + "</h2>" + " Is" + "<b>" + " not" + "</b>" + "</b>" + " available for email address.");
                } else {
                    $('.avalibility-email').html("<h2>" + "'" + email + "'" + "</h2>" + " Is" + "<b>" + " available " + "</b>" + "</b>" + "for email address.");
                }
            }
        });
    });
});

但我没有根据truefalse获得结果。

1 个答案:

答案 0 :(得分:0)

可能会在这条线上出错?

if (registeredemail.Count == 0 && registeredemail == null) {

必须是这样的:

if (registeredemail == null || registeredemail.Count == 0) {