Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class UserViewModel
- {
- [Display(Name = "User Name")]
- public string UserName { get; set; }
- public string Email { get; set; }
- [StringLength(int.MaxValue, MinimumLength = 6, ErrorMessage = "Password is at least 6 characters.")]
- public string Password { get; set; }
- [Display(Name = "Confirm Password")]
- [CompareAttribute("Password", ErrorMessage = "Password doesn't match.")]
- public string ConfirmPassword { get; set; }
- public string Role { get; set; }
- }
- public class AdminController : Controller
- {
- private ApplicationDbContext _context;
- public AdminController()
- {
- _context = new ApplicationDbContext();
- }
- // GET: Admin
- public ActionResult Index()
- {
- return View();
- }
- public ActionResult Create()
- {
- var viewModel = new UserViewModel();
- return View(viewModel);
- }
- public ActionResult CreateUser(UserViewModel viewModel)
- {
- var user = new ApplicationUser
- {
- Email = viewModel.Email,
- UserName = viewModel.UserName
- };
- return View("Index");
- }
- }
- @model HMSMVC.ViewModel.UserViewModel
- @{
- ViewBag.Title = "Create";
- }
- <h2>Create</h2>
- @using (Html.BeginForm())
- {
- @Html.AntiForgeryToken()
- <div class="form-horizontal">
- <h4>ApplicationUser</h4>
- <hr />
- @Html.ValidationSummary(true, "", new { @class = "text-danger" })
- <div class="form-group">
- @Html.LabelFor(model => model.UserName, htmlAttributes: new { @class = "control-label col-md-2" })
- <div class="col-md-10">
- @Html.EditorFor(model => model.UserName, new { htmlAttributes = new { @class = "form-control" } })
- @Html.ValidationMessageFor(model => model.UserName, "", new { @class = "text-danger" })
- </div>
- </div>
- <div class="form-group">
- @Html.LabelFor(model => model.Email, htmlAttributes: new { @class = "control-label col-md-2" })
- <div class="col-md-10">
- @Html.EditorFor(model => model.Email, new { htmlAttributes = new { @class = "form-control" } })
- @Html.ValidationMessageFor(model => model.Email, "", new { @class = "text-danger" })
- </div>
- </div>
- <div class="form-group">
- @Html.LabelFor(model => model.Password, htmlAttributes: new { @class = "control-label col-md-2" })
- <div class="col-md-10">
- @Html.EditorFor(model => model.Password, new { htmlAttributes = new { @class = "form-control", type = "password" } })
- @Html.ValidationMessageFor(model => model.Password, "", new { @class = "text-danger" })
- </div>
- </div>
- <div class="form-group">
- @Html.LabelFor(model => model.ConfirmPassword, htmlAttributes: new { @class = "control-label col-md-2" })
- <div class="col-md-10">
- @Html.EditorFor(model => model.ConfirmPassword, new { htmlAttributes = new { @class = "form-control", type = "password" } })
- @Html.ValidationMessageFor(model => model.ConfirmPassword, "", new { @class = "text-danger" })
- </div>
- </div>
- <div class="form-group">
- @Html.LabelFor(model => model.Role, htmlAttributes: new { @class = "control-label col-md-2" })
- <div class="col-md-10">
- @Html.DropDownListFor(model=>model.Role,new SelectList( new List<Object>
- {
- new{value = "Doctor", text = "Doctor"},
- new{value = "Receptionist", text = "Receptionist"}
- }, "value", "text"), "Select a Role",new{@class="form-control"})
- @Html.ValidationMessageFor(model => model.Role, "", new { @class = "text-danger" })
- </div>
- </div>
- <div class="form-group">
- <div class="col-md-offset-2 col-md-10">
- <input type="submit" value="Create" class="btn btn-default" />
- </div>
- </div>
- </div>
- }
- <div>
- @Html.ActionLink("Back to List", "Index")
- </div>
- @section scripts {
- @Scripts.Render("~/bundles/jqueryval")
- }
Add Comment
Please, Sign In to add comment