A.Mac
A.Mac

Reputation: 263

Asp.NET MVC DisplayName is not showing

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>

Upvotes: 0

Views: 608

Answers (2)

asmak9
asmak9

Reputation: 274

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

Upvotes: 0

jgasiorowski
jgasiorowski

Reputation: 1033

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

Upvotes: 1

Related Questions