找不到合适的方法来覆盖泛型类型为参数的方法的错误

时间:2018-09-26 15:58:24

标签: c#

我得到了-找不到合适的方法来覆盖泛型类型为参数的方法的错误。请帮助

public abstract class DocumentController<T> : Controller where T : class
{

    [HttpPost]
    public virtual Response Update([FromBody]T entity)
    {
        return true;
    }
}

public class DocumentDetailsController : DocumentController<Details>
{

    [HttpPost]
    public override Response Update([FromBody]T entity)
    {
        return false;
    }
}

1 个答案:

答案 0 :(得分:3)

您应该在Update方法中指定参数类型:

public override Response Update([FromBody]Details entity)

通用参数T在父类型中声明。您在此处将T指定为Details

DocumentDetailsController : DocumentController <Details>
相关问题