【问题标题】:The type or namespace name 'T' could not be found While passing as a parameter to MVC Controller作为参数传递给 MVC 控制器时,找不到类型或命名空间名称“T”
【发布时间】:2016-05-06 07:20:46
【问题描述】:

我将 T 作为参数传递,我遇到了这个构建错误。

这是我的要求

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

这是我的响应类

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; }        
}

请指导我如何使用此响应类作为参数,动态实体对象为“T”。

【问题讨论】:

  • 尝试在方法定义中指定 T。 eg.public JsonResult SetGridProperties(Response res){//代码}
  • 查看答案!

标签: asp.net-mvc parameters extension-methods jsonresult actionmethod


【解决方案1】:

需要在方法定义中指定T。

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

【讨论】:

    猜你喜欢
    • 2013-11-17
    • 2016-06-27
    • 1970-01-01
    • 2017-07-12
    • 2011-05-13
    • 2013-03-25
    • 2012-06-19
    相关资源
    最近更新 更多