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

9

5

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
Domain answered 27/11, 2020 at 9:55 Comment(0)
C
0

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>
Counterirritant answered 24/6, 2021 at 21:48 Comment(0)
A
13

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>
Amalee answered 21/1, 2022 at 13:1 Comment(0)
P
1

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>
Pipette answered 11/7, 2022 at 12:33 Comment(0)
R
1

I used a similar approach to debug as @Wil Campbell.

In my case, it was a mistake in a script definition. I had mistakenly changed a link that was going to be in a head (which uses href to load stylesheets) to a script (which uses src to load script files like javascript), but I forgot to change href to script when I did so.

Runck answered 12/7, 2023 at 12:52 Comment(1)
This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From ReviewPhylum
A
1

Check the quotes in your code.

If you missed quote/double quotes this is one of the reason why you are getting this error.

In my case this is a simple unnecesary quote was in the html tag:

  <div id="relatedCellExperiments" ">
  </div>
Adala answered 12/12, 2023 at 14:4 Comment(0)
C
0

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>
Counterirritant answered 24/6, 2021 at 21:48 Comment(0)
E
0

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

Elastic answered 20/11, 2021 at 21:37 Comment(0)
A
0

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...

Aili answered 26/5, 2022 at 10:53 Comment(0)
F
0

you are missing " somewhere in your form tag

Fireguard answered 23/9, 2023 at 22:27 Comment(1)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Castellanos
F
0

Encountered the same issue:

error RZ1034: Found a malformed 'head' tag helper. Tag helpers must have a start and end tag or be self closing.

Cause was <script/> instead of <script></script>

Fibrinolysin answered 13/10, 2024 at 13:8 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.