@model UserModel
@* Generated from Custom Template. *@
@* Model namespace using directive should be added to _ViewImports.cshtml. *@
@{
var containerDivClass = "container";
var dateTimePickerClass = "datetimepicker";
}
@{
ViewData["Title"] = "User Create";
}
<div class="@containerDivClass">
<h3>@ViewData["Title"]</h3>
<hr />
</div>
<div class="@containerDivClass">
@if (TempData["Message"] is not null)
{
<p class="text-danger">
@TempData["Message"]
</p>
}
<form asp-action="Create" autocomplete="off">
@Html.AntiForgeryToken()
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div class="row mb-3">
<label asp-for="UserName" class="col-2 col-form-label fw-bold"></label>
<div class="col-10">
<input asp-for="Record.UserName" class="form-control" />
<span asp-validation-for="Record.UserName" class="text-danger"></span>
</div>
</div>
<div class="row mb-3">
<label asp-for="Password" class="col-2 col-form-label fw-bold"></label>
<div class="col-10">
<input asp-for="Record.Password" class="form-control" />
<span asp-validation-for="Record.Password" class="text-danger"></span>
</div>
</div>
<div class="row mb-3">
<label asp-for="IsActive" class="col-2 col-form-label fw-bold"></label>
<div class="col-10 pt-2">
<input class="form-check-input" asp-for="Record.IsActive" /> @* check box will be generated since the model property type is bool *@
</div>
</div>
@* For enums, we need to generate the HTML tags explicitly, here we will generate radio buttons: *@
<div class="row mb-3">
<label asp-for="Status" class="col-2 col-form-label fw-bold"></label>
<div class="col-10">
<div class="form-check form-check-inline">
<input asp-for="Record.Status" type="radio" class="form-check-input" value="@((int)Statuses.Junior)" id="junior" checked /> @* rendering the enum's value part *@
<label class="form-check-label" for="junior">@Statuses.Junior</label> @* rendering the enum's text part *@
@* HTML for attribute of a label tag is used to focus or check the HTML element that has the same id attribute value *@
</div>
<div class="form-check form-check-inline">
<input asp-for="Record.Status" type="radio" class="form-check-input" value="@((int)Statuses.Senior)" id="senior" />
<label class="form-check-label" for="senior">@Statuses.Senior</label>
</div>
<div class="form-check form-check-inline">
<input asp-for="Record.Status" type="radio" class="form-check-input" value="@((int)Statuses.Master)" id="master" />
<label class="form-check-label" for="master">@Statuses.Master</label>
</div>
</div>
</div>
@*
The ViewData set in the action will be filled as items of the select HTML tag.
Generally an option tag with value "" and text "-- Select --" is added to force the user make a selection.
The selected role's Id value will be sent to the post action with the user model's Record.RoleId property.
*@
<div class="row mb-3">
<label asp-for="Role" class="col-2 col-form-label fw-bold"></label>
<div class="col-10">
<select asp-for="Record.RoleId" class="form-select" asp-items="ViewBag.RoleId"> @* drop down list *@
<option value="">-- Select --</option>
</select>
<span asp-validation-for="Record.RoleId" class="text-danger"></span>
</div>
</div>
@* Can be uncommented and used for many to many relationships. {Entity} may be replaced with the related entiy name in the controller and views. *@
@*
<div class="row mb-3">
<label asp-for="{Entity}Ids" class="col-2 col-form-label fw-bold"></label>
<div class="col-10">
<select multiple asp-for="{Entity}Ids" class="form-select" asp-items="ViewBag.{Entity}Ids"></select>
<span asp-validation-for="{Entity}Ids" class="text-danger"></span>
</div>
</div>
*@
<hr />
<div class="row mb-3">
<div class="offset-2 col-10">
<button type="submit" class="btn btn-primary">Save</button>
<button type="reset" class="btn btn-outline-primary">Reset</button>
<a asp-action="Index">Back to List</a>
</div>
</div>
</form>
</div>
@* All extra jQuery scripts and CSS must be added in the Scripts section therefore they are rendered after the jQuery script file reference in the _Layout.cshtml. *@
@section Scripts {
@*
For Client-Side Validation with Javascript withtout posting data to the server, _ValidationScriptsPartial partial view under Views/Shared folder can be added.
If not added, Server-Side Validation within the controller's action is performed.
This partial view can also be added while scaffolding a controller or a view by checking the "Reference script libraries" option.
*@
<partial name="_ValidationScriptsPartial" />
}