2012-01-03 51 views
1

我正在創建一個imageresult ..但「公共覆蓋無效ExecuteResult(ControllerContext上下文)」說:找不到合適的方法覆蓋。MVC 3:CustomResult()找不到合適的方法來覆蓋

我的課是這樣的..

public override void ExecuteResult(ControllerContext Context) 
    { 
     byte[] bytes; 
     string contentType = GetContentTypeFromFile(); 

     //if there's no context, stop the processing 
     if (Context == null) 
     { 
      throw new ArgumentNullException("context"); 
     } 

     //check for file 
     if(File.Exists(_path)){ 
      bytes = File.ReadAllBytes(_path); 
     } 
     else{ 
      throw new FileNotFoundException(_path); 
     } 


     // 
     HttpResponseBase response = Context.HttpContext.Response; 
     response.ContentType = contentType; 

     MemoryStream imageStream = new MemoryStream(bytes); 

     byte[] buffer = new byte[4096]; 

     while (true) 
     { 
      int read = imageStream.Read(buffer, 0, buffer.Length); 

      if (read == 0) 
       break; 

      response.OutputStream.Write(buffer, 0, read); 
     } 

     response.End(); 

    } 

回答

0

請問您的類的子類ActionResult?請嘗試以下操作:

using System.Web.Mvc; 

public class ImageResult : ActionResult 
{ 
    public override void ExecuteResult(ControllerContext Context) 
    { 
    ... 
    } 
} 
+0

是否覆蓋mvc 3中的工作? – 2012-01-03 13:00:09

+0

我做到了..但它不起作用.. – 2012-01-03 13:02:28

+0

@ Freetalk13覆蓋是.Net的一個功能,而不是MVC。它適用於所有版本的C#。 – 2012-01-03 13:05:01

相關問題