So i'm getting this error on my mvc project while working on my form. The error indicates that I haven't closed the form tag properly. However, as you'll see below, I have closed it properly.
<form method="post">
//form content below
</form>
I have added taghelpers in my ViewImports.cshtml
file as you can see below.
@using ServiceWebsite
@using ServiceWebsite.Models
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
I was facing the same problem but I have solve it with the following :
@using (Html.BeginForm("Login", "Main", FormMethod.Post))
{
<form>
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
@if (@ViewBag.Message != null)
{
<div style="border: 1px solid red">
@ViewBag.Message
</div>
}
<div class="mb-3">
<label class="form-label">@Html.LabelFor(UserBindingModel => UserBindingModel.UserName) </label>
</div>
}
Save it and it will disappear. I used this website as a reference.
Another example of functional form:
@model UserBindingModel
@{
ViewBag.Title = "Login";
}
<form asp-action="Login">
<div class="mb-3">
<label asp-for="UserName" class="form-label"></label>
<input type="text" class="form-control" asp-for="UserName">
</div>
<div class="mb-3">
<label asp-for="Password" class="form-label"></label>
<input asp-for="Password" class="form-control">
</div>
</form>