Developer technologies | ASP.NET Core | Other
A set of technologies in .NET for building web applications and web services. Miscellaneous topics that do not fit into specific categories.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Here's my code for the model and the view:
public class MyName
{
[Required(ErrorMessage = "Enter Full Name")]
public string Name { get; set; } = string.Empty;
}
***
@model MyName
<div class="container">
<div class="col-6">
<form method="post" asp-controller="Home" asp-action="PostIndex">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<input asp-for="Name" class="form-control" />
<span asp-validation-for="Name" class="text-danger"></span>
<input type="submit" class="btn btn-primary" value="Submit" />
</form>
</div>
</div>
When I run the app, I leave the input box alone (empty) and click submit. I'm looking to see the error message "Enter full name" show up on the view. But it doesn't. Am I doing something wrong, or forgot something?
A set of technologies in .NET for building web applications and web services. Miscellaneous topics that do not fit into specific categories.
Answer accepted by question author
Please add the following code at the last line of View and try:
@section Scripts {
@{await Html.RenderPartialAsync("_ValidationScriptsPartial");}
}