Difference between DisplayFor and DisplayNameFor:-

DisplayNameFor :- It shows the name of the property or the name used in the display attribute of the property.
Example 1:-
[Display(Name = 'Current User')]
public string UserName{get;set;}
@Html.DisplayNameFor(m => m.Username)
So in the browser it will display 'Current User'.
Example 2:-
public string UserName{get;set;}
So for example 2 in the browser it will display 'UserName'.
DisplayFor :- It is used for displaying model items or database items in the browser.
@foreach (var item in Model)
{
@Html.DisplayFor(modelItem => item.Email)
}
Let us see the above concept Step by Step:-

Step 1: Start creating new project and name it as "DisplayforDisplayNameFor"



Step 2: Select MVC template



Step 3: Now the project is created and you can view that in Solution Explorer.



Step 4: Right click Controller folder and add new controller



Step 5: Name that controller as "DisplayforDisplayNameForController"



Step 6: Right click Models folder and Create a User model class



Step 7: Now create a view for the DisplayForDisplayNameForController



Code Snippet: DisplayforDisplayNameForController.cs


public ActionResult Index()
{
User objusermodel = new User();
objusermodel.UserName = "USMTECHWORLD";
objusermodel.Email = "usmtechworld@gmail.com";
return View(objusermodel);
}

Code Snippet: DisplayforDisplayNameForController.cshtml


@model  DisplayForDisplayNameFor.Models.User
    
Usage of DisplayNameFor and DisplayFor :-
 @Html.DisplayNameFor(m => m.UserName)   @Html.DisplayFor(m=>m.UserName)

Step 8: Run and see the final output