Looping through view Model properties in a View

后端 未结 7 2297
南旧
南旧 2020-12-12 22:04

I have a painfully simple view model

public class TellAFriendViewModel
{
    public string Email1 { get; set; }
    public string Email2 { get; set; }
    pu         


        
7条回答
  •  心在旅途
    2020-12-12 22:05

    You can use Reflection to loop through each property of your model...as below

    Type type = Model.GetType(); // Model is the object you are binding with in your view
    PropertyInfo[] properties = type.GetProperties();
    foreach (var property in properties)
    {
        // Code to create your text box for the property
    }
    

    Hope this helps...

提交回复
热议问题