In some cases when properties is more than usual it is painful to copy and past some code after another to show all properties of a Model , So I want to know is there a way to show all properties of a Model dynamically. for example, we have this TestModel:
TestModel.cs
[Display(Name = "نام")]
[Required]
public string Name { get; set; }
[Display(Name = "ایمیل")]
[Required]
public string Email { get; set; }
[Display(Name = "شماره تماس")]
[Required]
public string PhoneNumber { get; set; }
Now I want to show both DisplayName and Value of this Model in razor, for example sth like this:
TestRazor.cshtml
@foreach (var Item in Model.GetType().GetProperties())
{
<div class="row">
<p class="label">@Item.DisplayName</p>
<p class="value">@Item.Value</p>
</div>
<br />
<br />
}