HtmlHelpers - Html.LabelFor/TextBoxFor/EditorFor 在新的 Dotnet 5 中
HtmlHelpers - Html.LabelFor/TextBoxFor/EditorFor in new Dotnet 5
我有一个从 Dotnetcore 3.1
迁移而来的 Dotnet 5.0
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 输入文本框,但 none 其他(HtmlHelper 语法).
- 即使 Intellisense 检测到 VS Code 中的关键字,这些助手是否不再可用?
- 我是不是遗漏了一些参考资料?
- 我是否遗漏了 ViewModel 的某些属性?
- 为什么要删除它,因为它们非常有用。
请注意,我不经常将 Dotnet MVC 与 Razor 一起使用,所以可能发生了一些我不知道的变化..
您需要使用剃刀语法。像这样
@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 =
"thisneither")
@Html.EditorFor(m => m.FullName, htmlAttributes: new { @class =
"thisneither")
<input type='submit' value="Submit" />
}
}
我有一个从 Dotnetcore 3.1
迁移而来的 Dotnet 5.0
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 输入文本框,但 none 其他(HtmlHelper 语法).
- 即使 Intellisense 检测到 VS Code 中的关键字,这些助手是否不再可用?
- 我是不是遗漏了一些参考资料?
- 我是否遗漏了 ViewModel 的某些属性?
- 为什么要删除它,因为它们非常有用。
请注意,我不经常将 Dotnet MVC 与 Razor 一起使用,所以可能发生了一些我不知道的变化..
您需要使用剃刀语法。像这样
@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 =
"thisneither")
@Html.EditorFor(m => m.FullName, htmlAttributes: new { @class =
"thisneither")
<input type='submit' value="Submit" />
}
}