2012-01-03 11 views
1

私はimageresultを作成していますが、 "public override void ExecuteResult(ControllerContext Context)"と言っています。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の作業を上書きしませんか? –

+0

私はそれをしました..しかしそれは動作しません.. –

+0

@ Freetalk13のオーバーライドは、ネットの機能ではなく、MVCです。これは、C#のすべてのバージョンで使用できます。 –

関連する問題