我们正在使用 ASP.Net 4 和 MVC 3 框架开发一个 Web 应用程序。我已经通过 NuGet 安装了 T4MVC,并且所有视图、控制器和静态内容都成功生成为强类型。
但是,当我尝试编译项目时,它会在生成的文件 T4MVC.cs 中引发错误,即:
'T4MVC_ViewResultBase.FindView(System.Web.Mvc.ControllerContext)':
return type must be 'System.Web.Mvc.ViewEngineResult' to match overridden member
'System.Web.Mvc.ViewResultBase.FindView(System.Web.Mvc.ControllerContext)'
这是生成的源代码:
[GeneratedCode("T4MVC", "2.0"), DebuggerNonUserCode]
public class T4MVC_ViewResultBase : System.Web.Mvc.ViewResultBase,
IT4MVCActionResult
{
public T4MVC_ViewResultBase(string area, string controller, string action):
base() {
this.InitMVCT4Result(area, controller, action);
}
protected override void FindView(System.Web.Mvc.ControllerContext context){}
public string Controller { get; set; }
public string Action { get; set; }
public RouteValueDictionary RouteValueDictionary { get; set; }
}
错误说:
protected override void FindView(System.Web.Mvc.ControllerContext context) { }
应该:
protected override ViewEngineResult
FindView(System.Web.Mvc.ControllerContext context) { }
但随后它引发了另一个编译错误,因为此方法应返回代码。
如果我们检查它继承自System.Web.Mvc.ViewResultBase的基类,它实际上声明了带有ViewEngineResult返回类型的FindView () :
public abstract class ViewResultBase : ActionResult
{
...
protected abstract ViewEngineResult FindView(ControllerContext context);
}
有人遇到这个错误吗?它与 MVC 版本有关,我们使用的是 MVC 3 吗?
非常感谢!塞尔吉