Search code examples
asp.net-mvcparametersextension-methodsjsonresultactionmethod

The type or namespace name 'T' could not be found While passing as a parameter to MVC Controller


I am passing T as a parameter & I am having this build error.

This is my requirement

public JsonResult SetGridProperties(Response<T> res)
    {
        res.ShowFilterRow = (!res.ShowFilterRow);
        return Json(true, JsonRequestBehavior.AllowGet);
    }

Here is my Response class

public class Response<T>
{
    public bool Status { get; set; }

    public string Message { get; set; }

    public T Data { get; set; }

    public List<T> DataList { get; set; }

    public MessageTypes MessageType { get; set; }

    public bool ShowFilterRow { get; set; }
    public bool AllowGroup { get; set; }        
}

Please guide me how can I use this Response class as a parameter with dynamic entity object as 'T'.


Solution

  • Need to specify T in the method definition.

    public JsonResult SetGridProperties<T>(Response<T> res)
    {
        res.ShowFilterRow = (!res.ShowFilterRow);
        return Json(true, JsonRequestBehavior.AllowGet);
    }