public class AddUserModel : PageModel { [BindProperty] public AddUserViewModel userModel { get; set; } [BindProperty] public UC.ADC.Core.Entities.SQL.User User { get; set; } public string SuccessMessage { get; set; } public AddUserModel(ADCContext db,OracleContext ora_db2) { _db = db; userModel = new AddUserViewModel(); } public async Task<IActionResult> OnPost() { if (ModelState.IsValid) { await _db.User.AddAsync(User); await _db.SaveChangesAsync(); SuccessMessage = "Form submitted successfully!"; return Page(); } } public void OnGet() { userModel.Branches = _db.Branch.ToList(); } } on adduser.cshtml @page "/AddUser" <form method="post"> <div class="form-group row"> <label for="branch-select" class="col-sm-1 col-form-label" style="font-size:15px;font-family: 'Open Sans', sans-serif;font-weight: bold;">Branch</label> <div class="col-sm-3"> <select id="branch-select" asp-for="User.iBranchCode" class="form-control" style=" margin-left:10px;font-size:15px;font-family: 'Open Sans' , sans-serif;font-weight: bold;"> <option value="">-- Select Branch --</option> @foreach (var branch in Model.userModel.Branches) { <option value="@branch.iBranchCode">@branch.vBranchDesc</option> } </select> </div> </div> <div class="form-group row" style="margin-left:200px;font-size:15px;font-family: 'Open Sans' , sans-serif;font-weight: bold;"> <button type="submit" class="col-sm-1 btn btn-primary">Submit</button> </div> </form
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)