ASP.NET MVC DisplayName未显示

发布于 2025-02-12 18:28:02 字数 454 浏览 2 评论 0 原文

我添加了显示名称,但是运行应用程序时没有显示。

员工.cs

using System.ComponentModel.DataAnnotations;
using System.ComponentModel;

 
[Required]
[DisplayName("First Name & Last Name")]
public string FullName { get; set; }

addemployee.cshtml

@model employee_creation.Models.Employee

@{
    ViewData["Title"] = "Add Employee";
}

 <label asp-for="FullName" class="form-label font-w600"></label>

I have added the display name however it is not showing up when I run the application.

Employee.cs

using System.ComponentModel.DataAnnotations;
using System.ComponentModel;

 
[Required]
[DisplayName("First Name & Last Name")]
public string FullName { get; set; }

AddEmployee.cshtml

@model employee_creation.Models.Employee

@{
    ViewData["Title"] = "Add Employee";
}

 <label asp-for="FullName" class="form-label font-w600"></label>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

绻影浮沉 2025-02-19 18:28:02

基于 docs 看起来您应该使用 [display> =“ name =”名字&amp; last名称“)]
在许多情况下,这些属性的起作用相同,但我们需要记住,这是两种不同的类型 - 我想标签助手不支持两者

Based on docs it looks like you should use [Display(Name = "First Name & Last Name")] instead.
In many scenarios these attributes works the same but we need to remember that those are two different types - and I guess Tag helpers does not support both

孤城病女 2025-02-19 18:28:02
<label asp-for="FullName" class="form-label font-w600"></label>

将始终显示“ 名字&amp;姓”。要在标签中获得实际值,请使用下面的代码IE

<label class="form-label font-w600">@Model.FullName</label>
<label asp-for="FullName" class="form-label font-w600"></label>

will always show "First Name & Last Name". To get the actual value inside label use below code i.e.

<label class="form-label font-w600">@Model.FullName</label>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文