I want to read value of a T type
public virtual ActionResult Edit(TEditDTO editedDTO)
{
if (!ModelState.IsValid) return View(editedDTO);
Try this,
var Id = prop.GetValue(editedDTO, null);
You should pass the instance of TEditDTO
to GetValue
method not the type instance.
var Id = prop.GetValue(editedDTO);
the PropertyInfo.GetValue method accepts as the first argument an instance of the type for which you want to read the value. if using an indexer you also need to specify an additional array argument to GetValue. since both arguments are required you need to pass null for the second one when reading a normal property. in your example you're passing a Type instance instead of a TEditDTO instance. use the code below.
var Id = prop.GetValue(editedDTO, null);
Try this:
public virtual ActionResult Edit(TEditDTO editedDTO)
{
if (!ModelState.IsValid) return View(editedDTO);
PropertyInfo prop = typeof(editedDTO).GetProperty("Id") ;
Object Id = prop.GetValue(editedDTO);
}