here is my regitration model :-
public class RegisterViewModel
{
[Required]
[EmailAddress]
[Display(Name = "Email")]
public string Email { get; set; }
public string FirstName { get; set; }
[Required]
public string MiddleName { get; set; }
[Required]
public string LastName { get; set; }
[Required]
public string Gender { get; set; }
[Required]
[DataType(DataType.Date)]
public string DOB { get; set; }
public string Profile { get; set; }
[Required]
[RegularExpression("^[0-9]{12}$")]
public decimal Mobile { get; set; }
[Required]
public string Address { get; set; }
[Required]
public string City { get; set; }
[Required]
public string State { get; set; }
[Required]
[StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)]
[DataType(DataType.Password)]
[Display(Name = "Password")]
public string Password { get; set; }
[DataType(DataType.Password)]
[Display(Name = "Confirm password")]
[Compare("Password", ErrorMessage = "The password and confirmation password do not match.")]
public string ConfirmPassword { get; set; }
}
here :-
public string Profile { get; set; }
is the property where i want to store the path of image
here is my controller :-
private ApplicationDbContext db = new ApplicationDbContext();
[AllowAnonymous]
public ActionResult Register()
{
ViewBag.state = db.allofstate.Select(C => new SelectListItem
{
Value = C.States,
Text = C.States
}).ToList();
return View();
}
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Register(RegisterViewModel model)
{
if (ModelState.IsValid)
{
var user = new ApplicationUser { UserName = model.Email, Email = model.Email, FirstName = model.FirstName, MiddleName = model.MiddleName, LastName = model.LastName, Gender = model.Gender, DOB = model.DOB, Profile = model.Profile, Mobile = model.Mobile, Address = model.Address, City = model.City, State = model.State };
var result = await UserManager.CreateAsync(user, model.Password);
using (ApplicationDbContext db = new ApplicationDbContext())
if (result.Succeeded)
{
await SignInManager.SignInAsync(user, isPersistent:false, rememberBrowser:false);
return RedirectToAction("Index", "Home");
}
AddErrors(result);
}
return View(model);
}
What I have tried:
i have tried with using byte but i want to store images path
because i want to retrive that image when perticular user logs in