Q:

How to use Html.LabelFor with dynamic expression?

My question is very simple.
I want to run for the property value of all in object. For Example:
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 ) 
}

How can I do what I wanted ? this way or other way,

A:

I haven't got my dev environment handy but try this anyhow
@{ var emptyViewModel = new Product(); 
   var props = obj.GetType().GetProperties();

foreach(var prop in props)
{   
    @Html.LabelFor(model => emptyViewModel, prop.Name.ToString())  
}
}

