Reputation: 9281
I'm new to ASP.NET MVC using Entity Framework and I'm trying to create a simple login system. At the moment I have UserProfile
model that I wish to model a login form off of.
UserProfile.cs
namespace MyProject.Areas.Admin.Models
{
public class UserProfile {
[Key]
public int UserID { get; set; }
[Required]
[Display(Name = "Username")]
public string Username { get; set; }
[Required]
[DataType(DataType.Password)]
[Display(Name = "Password")]
public string Password { get; set; }
public string FirstName { get; set; }
public string Surname { get; set; }
public string EmailAddress { get; set; }
public string Telephone { get; set; }
}
}
As my login form will only require a username and password, is it correct for me to create a separate model (for instance, a LoginModel
with just those properties, or should I contine to use the UserProfile
model?
It feels better for me to create a separate model to model the login submission, but then I run into the issues such as making them reference the same table?
Thanks
Upvotes: 2
Views: 76
Reputation: 60493
You should have only one Model
(Domain model), but different ViewModel
class.
The ViewModel
will only have the properties (from the Model) needed for a certain View
/Action
.
To manage mapping between Model
and ViewModel
(s), you should look at Mapping solutions (like AutoMapper, ValueInjecter...)
Upvotes: 4