unable to create HttpGet controller to find user detail using identity - c#

I have created authentication controller and there i was able to create HttpPost for login and logout but not HttpGet. what i'm trying is Only authenticated user can hit and return basic information about currently logged in user at a minimum Username,Staffid(if any)
i have created three role that is admin manager and staff.
namespace Web.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class AuthenticationController : ControllerBase
{
private readonly UserManager<User> userManager;
private readonly SignInManager<User> signInManager;
public object DefaultAuthenticationTypes { get; private set; }
public AuthenticationController(UserManager<User> userManager, SignInManager<User> signInManager)
{
this.userManager = userManager;
this.signInManager = signInManager;
}
[HttpPost("login")]
public async Task<ActionResult<UserDto>> Login(LoginDto dto)
{
var user = await userManager.FindByNameAsync(dto.UserName);
if (user == null)
{
return BadRequest();
}
var password = await signInManager.CheckPasswordSignInAsync(user, dto.Password, true);
if (!password.Succeeded)
{
return BadRequest();
}
await signInManager.SignInAsync(user, false, "Password");
return Ok(new UserDto
{
UserName = user.UserName
});
}
[HttpGet]
[Authorize]
public async Task<string> GetUserProfile()
{
var userName = await userManager.FindByNameAsync(HttpContext.User.Identity.Name);
var userId = userName.Id;
var roleId = User.IsInRole("Staff");
if (!(roleId.ToString() == "Staff"))
{
return userName.ToString();
}
return userId.ToString();
}
[HttpPost("logout")]
public async Task<ActionResult> logout()
{
await signInManager.SignOutAsync();
return Ok();
}
}
}

If you want to use HttpGet,Here is a demo:
Login:
[HttpGet("login")]
public async Task<IActionResult> Login(InputModel Input) {
return Ok();
}
InputModel:
public class InputModel
{
[Required]
[EmailAddress]
public string Email { get; set; }
[Required]
[DataType(DataType.Password)]
public string Password { get; set; }
[Display(Name = "Remember me?")]
public bool RememberMe { get; set; }
}
View(use method="get" on form):
<form id="account" method="get" asp-controller="Home" asp-action="Login">
<h4>Use a local account to log in.</h4>
<hr />
<div asp-validation-summary="All" class="text-danger"></div>
<div class="form-group">
<label asp-for="Input.Email"></label>
<input asp-for="Input.Email" class="form-control" />
<span asp-validation-for="Input.Email" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Input.Password"></label>
<input asp-for="Input.Password" class="form-control" />
<span asp-validation-for="Input.Password" class="text-danger"></span>
</div>
<div class="form-group">
<div class="checkbox">
<label asp-for="Input.RememberMe">
<input asp-for="Input.RememberMe" />
#Html.DisplayNameFor(m => m.Input.RememberMe)
</label>
</div>
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary">Log in</button>
</div>
</form>
result:
However,when you use HttpGet,your user login infomation will exposed in the url,so it is not safe,you'd better use HttpPost.
If you want to get user detail,you can use this:
var info = await _userManager.GetUserAsync(HttpContext.User);

I have fixed this issues by :
[HttpGet]
[Authorize]
public async Task<object> GetUserProfile()
{
var userName = await userManager.FindByNameAsync(HttpContext.User.Identity.Name);
var userId = userName.Id;
var role = await userManager.GetRolesAsync(userName);
if (User.IsInRole("Staff"))
{
return Ok(new
{
userName,
userId
});
}
return Ok(new
{
userName,
role
});

Related

Registration with .NET Core Identity name field error - "User name '' is invalid, can only contain letters or digits."

I have created a registration form with ASP.NET Core Identity, using the default fields ("Email", "Password", "Confirm Password") and a custom field "Name". When I enter a random string value into the name field and press "Register", I always receive the below error message:
"User name '' is invalid, can only contain letters or digits."
Things I have tried:
I have set an option on the 'User' object for AllowedUserNameCharacters, but this doesn't seem to make a difference:
services.Configure<IdentityOptions>(options =>
{
options.User.AllowedUserNameCharacters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._#+";
}
My registration controller:
[HttpPost]
public async Task<IActionResult> Register(RegisterViewModel model)
{
if (ModelState.IsValid)
{
var user = new ApplicationUser
{
Name = model.Name,
Email = model.Email
};
var result = await _userManager.CreateAsync(user, model.Password);
if (result.Succeeded)
{
await _signInManager.SignInAsync(user, isPersistent: false);
return RedirectToAction("index", "Home");
}
foreach (var error in result.Errors)
{
ModelState.AddModelError("", error.Description);
}
ModelState.AddModelError(string.Empty, "Invalid Login Attempt");
}
return View(model);
}
Regsitration View:
<form method="post">
<div asp-validation-summary="All" class="text-danger"></div>
<div class="form-group">
<label asp-for="Name"></label>
<input asp-for="Name" class="form-control" />
<span asp-validation-for="Name" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Email"></label>
<input asp-for="Email" class="form-control" />
<span asp-validation-for="Email" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Password"></label>
<input asp-for="Password" class="form-control" />
<span asp-validation-for="Password" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="ConfirmPassword"></label>
<input asp-for="ConfirmPassword" class="form-control" />
<span asp-validation-for="ConfirmPassword" class="text-danger"></span>
</div>
<button type="submit" class="btn-primary">Register</button>
</form>
My appDBContext:
public class AppDBContext : IdentityDbContext<ApplicationUser>
{
private readonly DbContextOptions _options;
public AppDBContext()
{
}
public AppDBContext(DbContextOptions options): base(options)
{
_options = options;
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (!optionsBuilder.IsConfigured)
{
optionsBuilder.UseSqlServer(
#"Server=(localdb)\mssqllocaldb;Database=Codefirst");
}
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<ApplicationUser>()
.Property(e => e.Name)
.HasMaxLength(250);
modelBuilder.Entity<ApplicationUser>()
.Property(e => e.Email)
.HasMaxLength(250);
}
}
My applicationuser.cs class:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Identity;
namespace SLE_System.Data
{
public class ApplicationUser : IdentityUser
{
public string Name { get; set; }
public string Email { get; set; }
public string Password { get; set; }
public string ConfirmPassword { get; set; }
}
}
If anyone has any ideas, these would be much appreciated?
Thanks,
Robert
"UserName" is invalid, can only contain letters or digits. is the default error message about UserName property. In your Regsitration View, There is no input for UserName, So when you use CreateAsync() method to register user, The project will validate your properties and find UserName property is null and return this error message.
So one simply method is give it a value when you register ApplicationUser.
[HttpPost]
public async Task<IActionResult> Register(RegisterViewModel model)
{
if (ModelState.IsValid)
{
var user = new ApplicationUser
{
Name = model.Name,
UserName = model.Name,
Email = model.Email
};
//.......
But please note that when you input Name property, You need to satisfy UserName's validation rules. The default rule is to only support the following characters
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._#+"
You can also custom it's validation rule by using:
services.Configure<IdentityOptions>(options =>
{
options.User.AllowedUserNameCharacters = "xxxxxx";
//..............
Here IdentiyUser Class is inherited
public class ApplicationUser : IdentityUser
{
public string Name { get; set; }
public string Email { get; set; }
public string Password { get; set; }
public string ConfirmPassword { get; set; }
}
And the IdentityUser class has following properties as per Microsoft documentation link
there is property UserName which is also inherited.
By default string(Non Nullable Properties) datatype have default data annotation [Required("AllowEmptyStrings"=true)].Since while send the registered data UserName is missing but it is required so it is throwing error.

How to Get Selected List of DropDownList from Database or Model and Populate in Dropdown on View

I am performing a Bitwise-Create operation on my modal(view) and I am to select a dropdown list of users from another table/model and bind to the view so I can forward the request to them. I want to select users based on a certain role, if possible: but I just want to select the users from the database table.
If you need any other model or controller, kindly prompt me so i add it.
Please help..
Below is my Code:
Cshtml Code for the Modal View:(Removed Other TextFields):
So where I have the select tags, i want to get the select list of users and add it.
<div class="row">
<div class="col-md-12">
<form asp-action="AddOrEdit" asp-route-id="#Model.BitwiseId" autocomplete="false" enctype="multipart/form-data">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div class="col-md-6">
<div class="form-group">
<label asp-for="AccountName" class="control-label"></label>
<input asp-for="AccountName" class="form-control" />
<span asp-validation-for="AccountName" class="text-danger"></span>
</div>
</div>
<div class="form-group">
<label asp-for="File" class="control-label"></label>
<input type="file" name="userfile" class="form-control" accept=".xlsx"/>
<span asp-validation-for="File" class="text-danger"></span>
</div>
<div class="form-group">
<label for="cars">Select 1st Approver </label>
<select name="group_heads" id="group_heads" class="form-control">
<option value="">Select</option>
<option value="2">Bobby</option>
</select>
</div>
<hr />
<div class="d-grid gap-2">
<input type="submit" value="Save" class="btn btn-primary" />
</div>
</form>
</div>
Code: Controller for the Bitwise - Add Method:
namespace BOGBitwiseApp.Controllers
{
public class BitwiseController : Controller
{
private readonly ApplicationDbContext _context;
public BitwiseController(ApplicationDbContext context)
{
_context = context;
}
public async Task<IActionResult> Index()
{
return View(await _context.Bitwises.ToListAsync());
}
// GET: Transaction/AddOrEdit(Insert)
// GET: Transaction/AddOrEdit/5(Update)
[NoDirectAccess]
public async Task<IActionResult> AddOrEdit(int id = 0)
{
if (id == 0)
return View(new BitwiseModel());
else
{
var bitwiseModel = await _context.Bitwises.FindAsync(id);
if (bitwiseModel == null)
{
return NotFound();
}
return View(bitwiseModel);
}
}
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> AddOrEdit(int id, [Bind("BitwiseId,..., Amount")] BitwiseModel bitwiseModel, ...)
{
if (ModelState.IsValid)
{
//New
if (id == 0)
{
string filename = userfile.FileName;
...
await userfile.CopyToAsync(stream);
var data = _context.Users.ToListAsync();
bitwiseModel.Date = DateTime.Now;
_context.Add(bitwiseModel);
await _context.SaveChangesAsync();
}
//Update
else
{
try
{
_context.Update(bitwiseModel);
await _context.SaveChangesAsync();
}
catch (DbUpdateConcurrencyException)
{
if (!BitwiseModelExists(bitwiseModel.BitwiseId))
{ return NotFound(); }
else
{ throw; }
}
}
return Json(new { isValid = true, html = Helper.RenderRazorViewToString(this, "_ViewAll", _context.Bitwises.ToList()) });
}
return Json(new { isValid = false, html = Helper.RenderRazorViewToString(this, "AddOrEdit", bitwiseModel) });
}
Model Code for Bitwise (Add):
public class BitwiseModel
{
[Key]
public int BitwiseId { get; set; }
[Required]
[Column(TypeName = "nvarchar(100)")]
[DisplayName("Customer Name")]
public string AccountName { get; set; }
[NotMapped]
[DisplayName("Invoice File")]
public IFormFile? File { get; set; }
}
**Model for Users Table:**
public class ApplicationUser : IdentityUser
{
public string? FirstName { get; set; }
public string? LastName { get; set; }
public int UsernameChangeLimit { get; set; } = 2;
public byte[]? ProfilePicture { get; set; }
}

Passing additional fields as part of PageRemote data annotation

I have a cshtml page in the server side project of my Blazor Webassembly solution for editing user accounts that looks like this:
#page
#model TimesheetExpense.Server.Areas.Identity.Pages.Account.EditModel
#{
ViewData["Title"] = "Edit User";
}
#using TimesheetExpense.Shared.Dtos
<h4>#ViewData["Title"]</h4>
<form id="user-form" method="post">
<input asp-for="Input.UserId" name="UserId" class="form-control" />
<div class="form-group">
<label asp-for="Input.FirstName"></label>
<input asp-for="Input.FirstName" class="form-control" />
<span asp-validation-for="Input.FirstName"></span>
</div>
<div class="form-group">
<label asp-for="Input.LastName"></label>
<input asp-for="Input.LastName" class="form-control" />
<span asp-validation-for="Input.LastName"></span>
</div>
<div class="form-group">
<label asp-for="Input.Email"></label>
<input asp-for="Input.Email" class="form-control" />
<span asp-validation-for="Input.Email"></span>
</div>
<button id="update-user-button" type="submit" class="btn btn-primary">Save</button>
</form>
#section Scripts {
<partial name="_ValidationScriptsPartial" />
}
In the code behind, I'm trying to do some custom validation on the email field to check that the email address hasn't been used by another account. However, I don't want it to flag an issue if that email address is in use by the account I'm currently editing.
public partial class EditModel : PageModel
{
private readonly UserManager<ApplicationUser> _userManager;
private readonly RoleManager<ApplicationRole> _roleManager;
private readonly IUnitOfWork _unitOfWork;
public EditModel(UserManager<ApplicationUser> userManager, RoleManager<ApplicationRole> roleManager, IUnitOfWork unitOfWork)
{
_userManager = userManager;
_roleManager = roleManager;
_unitOfWork = unitOfWork;
}
[BindProperty]
public InputModel Input { get; set; }
public class InputModel
{
[Required]
[EmailAddress]
[PageRemote(ErrorMessage = "Email address already in use.", HttpMethod = "POST", PageHandler = "CheckEmail", AdditionalFields = "UserId,__RequestVerificationToken")]
public string? Email { get; set; }
[Required]
public string? FirstName { get; set; }
[Required]
public string? LastName { get; set; }
public int UserId { get; set; }
}
private async Task LoadAsync(ApplicationUser user)
{
var userId = int.Parse(await _userManager.GetUserIdAsync(user));
Input = new InputModel
{
Email = user.Email,
FirstName = user.FirstName == null ? "" : user.FirstName,
LastName = user.LastName == null ? "" : user.LastName,
UserId = userId,
};
}
public async Task<IActionResult> OnGetAsync(string userId)
{
var user = await _userManager.FindByIdAsync(userId);
if (user == null)
{
return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
}
await LoadAsync(user);
return Page();
}
public JsonResult OnPostCheckEmail(int UserId)
{
var userViaId = _userManager.FindByIdAsync(UserId.ToString()).Result;
var userViaEmail = _userManager.FindByEmailAsync(Input.Email).Result;
bool valid;
if (userViaEmail == null)
valid = true;
else if (userViaEmail == userViaId)
valid = true;
else
valid = false;
return new JsonResult(valid);
}
public async Task<IActionResult> OnPostAsync(string userId)
{
//Code removed for brevity
}
}
Whenever OnPostCheckEmail is called, UserId is always 0, even though the correct user id is showing in the input field on my form. How do I get it to pull through the correct user id?
My project is ASP.NET Core (.net 6.0) and my pages are based on the scaffolded identity pages.

Role is null at Post request for ASP.NET Core Razor Pages

I have this Razor Pages which show a textbox and a button. Upon clicked, it will create/insert a Role into the table. Problem is when I put a breakpoint at the OnPostAsync method, role parameter is null.
This is my front-end code:
#page
#model CreateModel
#{
ViewData["Title"] = "Create";
}
<h1>Create Role</h1>
<hr />
<div class="row">
<div class="col-md-4">
<form asp-route-returnUrl="#Model.ReturnUrl" method="post">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div class="form-group">
<label asp-for="Input.Name"></label>
<input asp-for="Input.Name" class="form-control" />
<span asp-validation-for="Input.Name" class="text-danger"></span>
</div>
<div class="form-group">
<input type="submit" value="Create" class="btn btn-primary" />
</div>
</form>
</div>
</div>
This is my code-behind:
public class CreateModel : PageModel
{
private readonly RoleManager<IdentityRole> _roleManager;
public CreateModel(RoleManager<IdentityRole> roleManager)
{
_roleManager = roleManager;
}
[BindProperty]
public IdentityRole Name { get; set; }
public InputModel Input { get; set; }
public string ReturnUrl { get; set; }
public class InputModel
{
[Required]
[StringLength(100, ErrorMessage = "The {0} must be at least {2} and at max {1} characters long.", MinimumLength = 3)]
[Display(Name = "Role Name")]
public IdentityRole Name { get; set; }
//public string Name { get; set; }
}
public void OnGet(string returnUrl = null)
{
ReturnUrl = returnUrl;
}
public async Task<IActionResult> OnPostAsync(IdentityRole role) {
await _roleManager.CreateAsync(role);
return Page();
}
}
The problem may come from the returned type of IdentityRole, in the client, your browser doesn't know how to convert a variable type to IdentityRole. Some popular types are: string, int, List<T>...
So, in this case, I suggest to use a string instead.
public InputModel Input { get; set; }
public class InputModel
{
public string Name { get; set; }
}
public async Task<IActionResult> OnPostAsync() {
await _roleManager.CreateAsync(new IdentityRole { Name = Input.Name });
return Page();
}

Bundle IdentityUser to ticket

This is a homework assignment. Where I have to make a website with MVC 2.2 and Make it possible to make a ticket with some basic info and link IdentityUser to the ticket.
The Class:
public class Ticket
{
public int ID { get; set; }
[Required]
public string Klant { get; set; }
[Required]
public string Applicatie { get; set; }
[Required]
public string Onderwerp { get; set; }
[Required]
public string Omschrijving { get; set; }
public DateTime Datum { get; set; }
public string Status { get; set; }
}
The Controller:
public class TicketsController : Controller
{
private readonly ApplicationDbContext _context;
UserManager<IdentityUser> _userManager;
public TicketsController(UserManager<IdentityUser> userManager)
{
_userManager = userManager;
}
public TicketsController(ApplicationDbContext context)
{
_context = context;
}
// GET: Tickets
public async Task<IActionResult> Index()
{
return View(await _context.Ticket.ToListAsync());
}
This is added to the controller at the moment.
UserManager<IdentityUser> _userManager;
public TicketsController(UserManager<IdentityUser> userManager)
{
_userManager = userManager;
}
So I was asking myself how to do this and I would really appreciate it if someone knows what to do and can explain it well.
Thanks in advance.
If you need more info just ask.
Here is a working scenario for creating one ticket with one IdentityUser.
Ticket
public class Ticket
{
public int ID { get; set; }
[Required]
public string Klant { get; set; }
[Required]
public string Applicatie { get; set; }
[Required]
public string Onderwerp { get; set; }
[Required]
public string Omschrijving { get; set; }
public DateTime Datum { get; set; }
public string Status { get; set; }
public string IdentityUserId { get; set; }
public virtual IdentityUser IdentityUser { get; set; }
}
ApplicationDbContext
public class ApplicationDbContext : IdentityDbContext
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
: base(options)
{
}
public DbSet<Ticket> Tickets { get; set; }
protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder);
builder.Entity<Ticket>().HasOne(t => t.IdentityUser).WithMany();
}
}
TicketsController
public class TicketsController : Controller
{
private readonly ApplicationDbContext _context;
private readonly UserManager<IdentityUser> _userManager;
public TicketsController(ApplicationDbContext context
, UserManager<IdentityUser> userManager)
{
_context = context;
_userManager = userManager;
}
// GET: Tickets
public async Task<IActionResult> Index()
{
var applicationDbContext = _context.Tickets.Include(t => t.IdentityUser);
return View(await applicationDbContext.ToListAsync());
}
// GET: Tickets/Details/5
public async Task<IActionResult> Details(int? id)
{
if (id == null)
{
return NotFound();
}
var ticket = await _context.Tickets
.Include(t => t.IdentityUser)
.FirstOrDefaultAsync(m => m.ID == id);
if (ticket == null)
{
return NotFound();
}
return View(ticket);
}
// GET: Tickets/Create
public IActionResult Create()
{
ViewData["IdentityUserId"] = new SelectList(_context.Users, "Id", "Id");
return View();
}
// POST: Tickets/Create
// To protect from overposting attacks, please enable the specific properties you want to bind to, for
// more details see http://go.microsoft.com/fwlink/?LinkId=317598.
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Create([Bind("ID,Klant,Applicatie,Onderwerp,Omschrijving,Datum,Status,IdentityUserId")] Ticket ticket)
{
if (ModelState.IsValid)
{
_context.Add(ticket);
await _context.SaveChangesAsync();
return RedirectToAction(nameof(Index));
}
ViewData["IdentityUserId"] = new SelectList(_context.Users, "Id", "Id", ticket.IdentityUserId);
return View(ticket);
}
// GET: Tickets/Edit/5
public async Task<IActionResult> Edit(int? id)
{
if (id == null)
{
return NotFound();
}
var ticket = await _context.Tickets.FindAsync(id);
if (ticket == null)
{
return NotFound();
}
ViewData["IdentityUserId"] = new SelectList(_context.Users, "Id", "Id", ticket.IdentityUserId);
return View(ticket);
}
// POST: Tickets/Edit/5
// To protect from overposting attacks, please enable the specific properties you want to bind to, for
// more details see http://go.microsoft.com/fwlink/?LinkId=317598.
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Edit(int id, [Bind("ID,Klant,Applicatie,Onderwerp,Omschrijving,Datum,Status,IdentityUserId")] Ticket ticket)
{
if (id != ticket.ID)
{
return NotFound();
}
if (ModelState.IsValid)
{
try
{
_context.Update(ticket);
await _context.SaveChangesAsync();
}
catch (DbUpdateConcurrencyException)
{
if (!TicketExists(ticket.ID))
{
return NotFound();
}
else
{
throw;
}
}
return RedirectToAction(nameof(Index));
}
ViewData["IdentityUserId"] = new SelectList(_context.Users, "Id", "Id", ticket.IdentityUserId);
return View(ticket);
}
// GET: Tickets/Delete/5
public async Task<IActionResult> Delete(int? id)
{
if (id == null)
{
return NotFound();
}
var ticket = await _context.Tickets
.Include(t => t.IdentityUser)
.FirstOrDefaultAsync(m => m.ID == id);
if (ticket == null)
{
return NotFound();
}
return View(ticket);
}
// POST: Tickets/Delete/5
[HttpPost, ActionName("Delete")]
[ValidateAntiForgeryToken]
public async Task<IActionResult> DeleteConfirmed(int id)
{
var ticket = await _context.Tickets.FindAsync(id);
_context.Tickets.Remove(ticket);
await _context.SaveChangesAsync();
return RedirectToAction(nameof(Index));
}
private bool TicketExists(int id)
{
return _context.Tickets.Any(e => e.ID == id);
}
}
Create.cshtml
#model CoreIdentity2.Models.Ticket
#{
ViewData["Title"] = "Create";
}
<h1>Create</h1>
<h4>Ticket</h4>
<hr />
<div class="row">
<div class="col-md-4">
<form asp-action="Create">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div class="form-group">
<label asp-for="Klant" class="control-label"></label>
<input asp-for="Klant" class="form-control" />
<span asp-validation-for="Klant" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Applicatie" class="control-label"></label>
<input asp-for="Applicatie" class="form-control" />
<span asp-validation-for="Applicatie" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Onderwerp" class="control-label"></label>
<input asp-for="Onderwerp" class="form-control" />
<span asp-validation-for="Onderwerp" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Omschrijving" class="control-label"></label>
<input asp-for="Omschrijving" class="form-control" />
<span asp-validation-for="Omschrijving" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Datum" class="control-label"></label>
<input asp-for="Datum" class="form-control" />
<span asp-validation-for="Datum" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Status" class="control-label"></label>
<input asp-for="Status" class="form-control" />
<span asp-validation-for="Status" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="IdentityUserId" class="control-label"></label>
<select asp-for="IdentityUserId" class ="form-control" asp-items="ViewBag.IdentityUserId"></select>
</div>
<div class="form-group">
<input type="submit" value="Create" class="btn btn-primary" />
</div>
</form>
</div>
</div>
<div>
<a asp-action="Index">Back to List</a>
</div>
#section Scripts {
#{await Html.RenderPartialAsync("_ValidationScriptsPartial");}
}

Categories

Resources