微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

HtmlHelpers - 新 Dotnet 5 中的 Html.LabelFor/TextBoxFor/EditorFor

如何解决HtmlHelpers - 新 Dotnet 5 中的 Html.LabelFor/TextBoxFor/EditorFor

我有一个Dotnet 5.0 迁移的 Dotnetcore 3.1 MVC 项目,但使用 Html.LabelFor,Html.TextBoxFor,Html.EditorFor 的表单不显示输入。

查看:

@model UpdateProductsviewmodel;

@{
    using (Html.BeginForm("UpdateProducts","TheController",FormMethod.Post))
    {
        <p>browse File:</p>
        Html.LabelFor(m => m.FullName,htmlAttributes: new { @class = "this-doesnt-show"});
        Html.TextBoxFor(m => m.FullName,htmlAttributes: new { @class = "this-neither");
        Html.EditorFor(m => m.FullName,htmlAttributes: new { @class = "this-neither");
        <div>
            <label asp-for="FullName" class="this-shows-with-asp-for"></label>
            <input asp-for="FullName" class="this-shows-with-asp-for" />
        </div>
        <input type='submit' value="Submit" />
    }
}

型号:

public class UpdateProductsviewmodel{
  // truncated

  public string FullName { get; set; }
}

在我上面的示例中,我有模型和视图。

但是之前我把它改成asp-for,我把它们当作Html.LabelFor,Html.EditorFor,Html.TextBoxFor这些在 Dotnet 5 中再也没有出现过

当我使用语法 <input asp-for=""> | <label asp-for=""> 时,控件显示,即 1x 标签,1x 输入文本框,但 其他都没有(HtmlHelper 语法)

  • 即使 Intellisense 检测到 VS Code 中的关键字,这些 Helper 是否不再可用?
  • 我是否遗漏了一些参考资料?
  • 我是否缺少 viewmodel 上的某些属性
  • 为什么要删除它,因为它们非常有用。

请注意,我不会经常将 Dotnet MVC 与 Razor 一起使用,所以可能发生了一些我不知道的变化..

解决方法

您需要使用剃刀语法。像这样

=[@[Weight (g)]]*[@[Calories Original]]/[@[Reference Weight]]

}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。