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

Viewed 4177

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
5 Answers

May you have an unclosed quotation.

The same problem happened to me because I haven't closed " in readonly="readonly

 <form class="form customized-bg-color" asp-action="Create" method="post">
       <div class="col-lg-3  ">
                    <input type="text" class="form-control " id="Total" readonly="readonly />
                </div>        
        </form>

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>

I think you should check the href attribute of Your stylesheets and images.

I also hit this "error", VS 2022 .Net 6 project, also with a well-formed, uh, form :) I removed the form tag & closing tag, rebuilt the project, then added them back in. Built just fine, issue did not reoccur. Depending on what you are trying to to, I'd try that before doing any major code changes...

the Form tag and its closing SHOULD be IN its container if it has one, I had the same problem. your form tag should Not be Like this

<div>
<form>
</div>
</form>

Correct:

<div>
  <form>
  </form>
</div>

Related