PLEASE HELP ME NOW. I must submit my project tomorrow
For 2 weeks i haven't made a successful save. what is wrong with my codes? i have this error:
The Action results task
<pre>
[AllowAnonymous]
public ActionResult Register()
{
ViewBag.RoleName = new SelectList(db.Roles, "RoleName", "RoleName");
return View();
}
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Register(RegisterViewModel model, DateTime? EmploymentEndDate = null)
{
if (ModelState.IsValid)
{
var user = new ApplicationUser {
UserName = model.Email,
Email = model.Email };
var result = await UserManager.CreateAsync(user, model.Password);
if (result.Succeeded)
{
using (var context = new TimeSheetsEntities())
{
var u = new Users
{
UserId = model.UserId,
SocialSecurityNumber = model.SocialSecurityNumber,
FirstName = model.FirstName,
LastName = model.LastName,
Address1 = model.Address1,
ZipCode = model.ZipCode,
City = model.City,
PhoneNumber1 = model.PhoneNumber1,
PhoneNumber2 = model.PhoneNumber2,
EmploymentStartDate = model.EmploymentStartDate,
EmploymentEndDate = model.EmploymentEndDate,
Email = model.Email,
Password = model.Password,
RoleName = model.RoleName,
};
context.Users.Add(u);
context.SaveChanges();
}
await SignInManager.SignInAsync(user, isPersistent:false, rememberBrowser:false);
return RedirectToAction("Index", "Home");
}
AddErrors(result);
}
return View(model);
}
The class models:
public class RegisterViewModel
{
[Required]
[Range(10000 - 99999, Double.MaxValue, ErrorMessage = "Create 5 digit UserId")]
[Display(Name = "User Identification")]
public int UserId { get; set; }
[Required]
[Display(Name = "Social Security number")]
public string SocialSecurityNumber { get; set; }
[Required]
[Display(Name = "Firstname")]
public string FirstName { get; set; }
[Required]
[Display(Name = "Lastname")]
public string LastName { get; set; }
[Required]
[Display(Name = "Adress Line 1")]
public string Address1 { get; set; }
[Required]
[Display(Name = "Adress Line 2")]
public string Address2 { get; set; }
[Required]
[Display(Name = "Postal code")]
public string ZipCode { get; set; }
[Required]
[Display(Name = "City")]
public string City { get; set; }
[Required]
[Display(Name = "Telephone number")]
public string PhoneNumber1 { get; set; }
[Required]
[Display(Name = "Telephon number")]
public string PhoneNumber2 { get; set; }
[Required]
[Display(Name = "Date of employment")]
public DateTime EmploymentStartDate { get; set; }
[Required]
[Display(Name = "End of Employment")]
public DateTime? EmploymentEndDate { get; set; }
[Required]
[EmailAddress]
[Display(Name = "Email")]
public string Email { 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; }
[Required]
[Display(Name = "Role")]
public string RoleName { get; set; }
Also save to this model class
<pre>public partial class Users
{
public Users()
{
this.Projects = new HashSet<Projects>();
this.Stampings = new HashSet<Stampings>();
this.TimesheetEntries = new HashSet<TimesheetEntries>();
this.UserProjects = new HashSet<UserProjects>();
}
public int UserId { get; set; }
public string SocialSecurityNumber { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Address1 { get; set; }
public string Address2 { get; set; }
public string ZipCode { get; set; }
public string City { get; set; }
public string PhoneNumber1 { get; set; }
public string PhoneNumber2 { get; set; }
public System.DateTime EmploymentStartDate { get; set; }
public Nullable<System.DateTime> EmploymentEndDate { get; set; }
public string Email { get; set; }
public string Password { get; set; }
public string RoleName { get; set; }
public virtual ICollection<Projects> Projects { get; set; }
public virtual Roles Roles { get; set; }
public virtual ICollection<Stampings> Stampings { get; set; }
public virtual ICollection<TimesheetEntries> TimesheetEntries { get; set; }
public virtual ICollection<UserProjects> UserProjects { get; set; }
}
The error
The model item passed into the dictionary is of type 'WebTime_Sheet.Models.RegisterViewModel', but this dictionary requires a model item of type 'WebTime_Sheet.Models.Users'.