Looping through view Model properties in a View

后端 未结 7 2257
南旧
南旧 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:16

    You should access

    ViewData.ModelMetadata.Properties. No reason to double the reflection effort, plus it figures out DataAttributes metadata for you.

    @foreach(var property in ViewData.ModelMetadata.Properties)
    {
        
    @Html.Editor(property.PropertyName)
    }

提交回复
热议问题