我們正在開發一個帶有ASP.Net 4的網絡應用程序。我已經通過NuGet安裝了T4MVC,所有視圖,控制器和靜態內容都成功生成爲強類型。在MVC 3項目中使用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的基類,它實際上宣告FindView()與ViewEngineResult返回類型:
public abstract class ViewResultBase : ActionResult
{
...
protected abstract ViewEngineResult FindView(ControllerContext context);
}
有沒有人有這個錯誤?有沒有與MVC版本有關,我們正在使用MVC 3嗎?
非常感謝! Sergi
嗯。這很棘手。不,沒有與版本,t4mvc適用於我的mvc3應用程序。希望大衛Ebbo會回答這個=) – gideon 2011-04-06 19:41:26