routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "myuser", action = "Index", id = UrlParameter.Optional }
);
using System.ComponentModel.DataAnnotations;
using System.Web.Mvc;
using System.ComponentModel.DataAnnotations.Schema;
[Required]
[StringLength(20, MinimumLength = 4, ErrorMessage = "Must be at least 4 characters long.")]
[Remote("checkusername", "myuser")]
public string username { get; set; }
[Required]
public string firstname { get; set; }
public string lastname { get; set; }
[Required]
public string address { get; set; }
[Required]
[DataType(DataType.PhoneNumber)]
[StringLength(10, MinimumLength = 10, ErrorMessage = "{0}: it should be 10 digits")]
public Nullable phone { get; set; }
[Required(ErrorMessage = "{0} required")]
[DataType(DataType.EmailAddress)]
[Display(Name = "Email")]
[RegularExpression(@"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*", ErrorMessage = "Invalid email")]
[Remote("checkemail", "myuser", ErrorMessage = "Already in use!")]
[StringLength(100, ErrorMessage = "{0}: 100 is the limit")]
public string email { get; set; }
public Nullable isactive { get; set; }
[Required]
[DataType(DataType.Password)]
public string password { get; set; }
[Required]
[NotMapped]
[System.ComponentModel.DataAnnotations.Compare("password", ErrorMessage = "Password doesn't match.")]
[DataType(DataType.Password)]
public string confirmpassword { get; set; }
public JsonResult checkusername(string username)
{
var data = db.users.Where(p => p.username.Equals(username, StringComparison.CurrentCultureIgnoreCase)).FirstOrDefault();
if (data != null)
{
return Json("Sorry, this name already exists", JsonRequestBehavior.AllowGet);
}
else
{
return Json(true, JsonRequestBehavior.AllowGet);
}
}
public JsonResult checkemail(string email)
{
var result = true;
var user = db.users.Where(x => x.email == email).FirstOrDefault();
if (user != null)
result = false;
return Json(result, JsonRequestBehavior.AllowGet);
}