I want to read value of a T type
public virtual ActionResult Edit(TEditDTO editedDTO)
{
if (!ModelState.IsValid) return View(editedDTO);
var t = editedDTO.GetType();
var prop = t.GetProperty("Id") ;
var Id = prop.GetValue(t); // get exception
}
but get
Object does not match target type
You should pass the instance of TEditDTO
to GetValue
method not the type instance.
var Id = prop.GetValue(editedDTO);
Try this,
var Id = prop.GetValue(editedDTO, null);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With