Asp.net mvc 如何将Html.LabelFor与动态表达式一起使用?
我的问题很简单 我想为all in对象的属性值运行。例如:Asp.net mvc 如何将Html.LabelFor与动态表达式一起使用?,asp.net-mvc,reflection,lambda,Asp.net Mvc,Reflection,Lambda,我的问题很简单 我想为all in对象的属性值运行。例如: 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 i
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 )
}
我怎么能做我想做的?通过这种方式或其他方式,我手头没有开发环境,但无论如何都要尝试一下
@{ var emptyViewModel = new Product();
var props = obj.GetType().GetProperties();
foreach(var prop in props)
{
@Html.LabelFor(model => emptyViewModel, prop.Name.ToString())
}
}
谢谢你,彼得。它在跑。