Dynamically call textboxfor with reflection

后端 未结 2 452
旧时难觅i
旧时难觅i 2021-01-07 05:12

The end result of what I am trying to do is build a form dynamically by reflecting an object and it\'s properties.

I\'ve created HtmlHelper methods that call TextBo

2条回答
  •  一个人的身影
    2021-01-07 05:54

    To get a property using reflection, use code like this:

    var prop = model_type.GetProperty(property_name);
    //then in your loop:
    prop.GetValue(model, null)
    

    Or if you're only going to get the property from one object, make it one line:

    model_type.GetProperty(property_name).GetValue(model, null);
    

提交回复
热议问题