The code is:
CreateNew.cshtml:
@Anonymous
@默 Project.Pages.PersonalPage.CreateNew
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@{
ViewData["Title"] = "Create new";
Layout = "_Layout";
}
<div class="row">
<div class="col-md-8">
<form method="post" >
<h4>Create New:</h4>
<hr />
<div asp-validation-summary="All" class="text-danger"></div>
<div class="form-group">
<label asp-for="Input.Category"></label>
<select asp-for="Input.Category" class="form-control">
<option value="" >=== Select ===</option>
<option value="Value 1"> Value 1</option>
<option value=" Value 2"> Value 2</option>
<option value=" Value 3"> Value 3</option>
</select>
<span asp-validation-for="Input.Category" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Input.Title"></label>
<input asp-for="Input.Title" class="form-control" />
<span asp-validation-for="Input.Title" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Input.Question"></label>
<textarea id="editor" asp-for="Input.Question" class="form-control"></textarea>
<span asp-validation-for="Input.Question" class="text-danger"></span>
</div>
<button type="submit" class="btn btn-primary">Create</button>
</form>
</div>
</div>
@section Scripts{
<partial name="_ValidationScriptsPartial" />
}
------------------------
CreateNew.cshtml.cs:
[AllowAnonymous]
public class CreateNew : PageModel
{
[BindProperty]
public InputModel Input { get; set; }
public string ReturnUrl { get; set; }
public class InputModel
{
[Required]
public string Category { get; set; }
[Required]
public string Title { get; set; }
[Required]
[Display(Name = "Question")]
public string QuestionA { get; set; }
}
…