找到了格式错误的“表单”标签助手。标签助手必须有一个开始和结束标签或自闭

所以我在处理我的表单时在我的 mvc 项目上遇到了这个错误。该错误表明我没有正确关闭表单标签。但是,正如您将在下面看到的,我已正确关闭它。

<form method="post">

  //form content below

</form>

我在我的 ViewImports.cshtml 文件中添加了 taghelpers,如下所示。

@using ServiceWebsite
@using ServiceWebsite.Models
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
stack overflow Found a malformed 'form' tag helper. Tag helpers must have a start and end tag or be self closing
原文答案
author avatar

接受的答案

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>


答案:

作者头像

愿您有一个未封闭的报价。

同样的问题也发生在我身上

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

作者头像

Form 标签及其关闭应该在它的容器中,如果它有一个,我有同样的问题。你的表单标签不应该是这样的

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

正确的:

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