Found a malformed 'form' tag helper. Tag helpers must have a start and end tag or be self closing

Issue

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

Solution

I was facing the same problem but I have solve it with the following :

  • Either using pure html form
  • Or inject Helper tags into the form like so
@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>

Answered By – Rose Riyadh

Answer Checked By – Candace Johnson (AngularFixing Volunteer)

Leave a Reply

Your email address will not be published.