提供在mvc项目中查找现有电子邮件ID的解决方案 [英] Give a solution for find existing email id in mvc project

查看:70
本文介绍了提供在mvc项目中查找现有电子邮件ID的解决方案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



i想找到输入的电子邮件地址是否存在

我的剧本


i want find the entering email address is existed or not
my script

<script>
    function ABC() {
        var email = $('#Email').val();
        //alert(email);
        $.ajax({
            url: '/person/CheckEmail',
            type: 'GET',
            data: 'email='+ email,//{email:email},         /*'id="' + email+'",*/
            cache: false,
            success: function (html) {
                alert(html);
            }
        });
    }
</script>



personContoller


personContoller

public string CheckEmail(string email)
      {
         //how to write code for find existing email id
      }





数据库名称人物

表名人物

表格字段是..

名称

电子邮件

职业

年龄



请帮帮我



问候

AR



database name person
table name people
table fields are..
name
email
profession
age

please help me

Regards
AR

推荐答案

' #Email')。val();
// alert(email);
('#Email').val(); //alert(email);


.ajax({
url:' / person / CheckEmail'
type :' GET'
data:' email =' + email, // {email:email},/ *'id ='+ email +',* /
cache: false
成功:功能(html){
alert(html);
}
});
}
< / 脚本 >
.ajax({ url: '/person/CheckEmail', type: 'GET', data: 'email='+ email,//{email:email}, /*'id="' + email+'",*/ cache: false, success: function (html) { alert(html); } }); } </script>



personContoller


personContoller

public string CheckEmail(string email)
      {
         //how to write code for find existing email id
      }





数据库名称人物

表名人物

表格字段是..

名称

电子邮件

职业

年龄



请帮帮我



问候

AR



database name person
table name people
table fields are..
name
email
profession
age

please help me

Regards
AR


对于演示,我创建了类似的示例。首先我创建了Person类作为模型和Dummy数据库:

For demo I have created similar example. First I created Person class as model and Dummy database:
 public class Person
 {
     public string Name { get; set; }
     [DataType(DataType.EmailAddress)]
     public string Email { get; set; }
     public string Profession { get; set; }
     public int Age { get; set; }

 }

public class DummyDatabase
 {
     public List<Person> GetAllPersons()
     {
         return new List<Person> {
             new Person () {  Name = "Arti", Email = "arti@abc.com",
                              Profession = "Engineer", Age = 25},
             new Person () {  Name = "Deepak", Email = "deepak@gmail.com",
                              Profession = "Engineer", Age = 25}

         };
     }
 }





现在在控制器中我写的方法如下:



Now In controller I am writing the method like:

public string CheckEmail(string email)
       {
           DummyDatabase db = new DummyDatabase();
           var allPerson = db.GetAllPersons();

           var result = (from p in allPerson 
                            where p.Email == email select p).ToList();

           if (result.Count > 0)
           {
               return "Exist";
           }
           else
           {
               return "Does not exist";
           }
       }





希望它能帮助你在代码中实现一个想法。 />




使用ADO.NET或Entity Framework连接到数据库。

对于Entity Framework,请访问:

带有实体框架的简单示例 [ ^ ]



http://msdn.microsoft.com/en-us/data/ee712907.aspx



对于ADO.NET,请访问:为初学者使用ADO.NET [ ^ ]


这篇关于提供在mvc项目中查找现有电子邮件ID的解决方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆