1

私の質問はとても簡単です。

オブジェクト内のすべてのプロパティ値に対して実行したいと思います。例えば:

public class Product
{
    public int ProductId {get;set;}
    public string Name {get;set;}
    public string Content {get;set;}
}

var obj = new Product();
var props = obj.GetType().GetProperties();

foreach(var prop in props)
{
    @Html.LabelFor( ....... ) // Need to run for active property.
    // such as @Html.LabelFor( x => prop ) 
}

どうすればやりたいことができますか?このようにまたは他の方法で、

4

1 に答える 1

2

開発環境が手元にありませんが、とにかくこれを試してください

@{ var emptyViewModel = new Product(); 
   var props = obj.GetType().GetProperties();

foreach(var prop in props)
{   
    @Html.LabelFor(model => emptyViewModel, prop.Name.ToString())  
}
}
于 2012-05-14T09:46:04.723 に答える