public class Customer
{
public int Id{ get; set; }
[Required]
[StringLength(255)]
public string Name { get; set; }
public bool IsSubscribeToNesletter { get; set; }
public MembershipType membershipType { get; set; }
[Display(Name = "Membership Type")]
public byte membershipTypeId { get; set; }
[Display(Name = "Date or Birth")]
public string Birthday { get; set; }
}
public ActionResult Save(Customer customer)
{
if (!ModelState.IsValid)
{
var viewModel = new CustomerFormViewModel
{
customer = customer,
MembershipTypes = _context.membershipType.ToList()
};
return View("CustomerForm", viewModel);
}
<div class = "form-group">
@Html.LabelFor(m => m.customer.Name)
@Html.TextBoxFor(m => m.customer.Name, new { @class = "form-control" })
@Html.ValidationMessageFor(m => m.customer.Name);
</div>