Home > Enterprise >  Asp.NET MVC DisplayName is not showing
Asp.NET MVC DisplayName is not showing

Time:07-06

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" ></label>

CodePudding user response:

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

CodePudding user response:

<label asp-for="FullName" ></label>

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

<label >@Model.FullName</label>
  • Related