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();
}
是否覆蓋mvc 3中的工作? – 2012-01-03 13:00:09
我做到了..但它不起作用.. – 2012-01-03 13:02:28
@ Freetalk13覆蓋是.Net的一個功能,而不是MVC。它適用於所有版本的C#。 – 2012-01-03 13:05:01