2012-05-19 31 views
0

你好我是从的ActionResultMVC3 Handler.ashx

ViewBag.IMG = "Handler.ashx?img=" + imagetest + 

然而调用Handler.ashx,如果ActionResult的是指数,它工作正常,

http://localhost:11111/ImageHandler.ashx?img=image 

如果是其他任何名字,它不会调用Handler!

http://localhost:11111/ActionReult(name)/ImageHandler.ashx?img=image 

它在URL中添加ActionResult名称。

任何想法,在此先感谢。

+0

我们展示的代码......否则说什么正在发生的事情就像是讲述一个机械师什么不对您的引擎制作我的声音。 –

回答

0

然后我不明白错误,.ashx代替,可以使用控制器返回FileContentResult或FileResult到File或FileStreamResult到File。

样品

public FileContentResult Index() 
{ 
    var Resim = new WebClient().DownloadData("https://dosyalar.blob.core.windows.net/dosya/kartalisveris.gif"); 
    return new FileContentResult(Resim, "image/png"); //* With {.FileDownloadName = "Höbölö"} 
} 

或者

public FileResult Index() 
{ 
    FileInfo fi = new FileInfo(Server.MapPath("~/Content/imgs/fillo_kargo.png")); 
    return File(fi.OpenRead, "image/png"); //or .FileDownloadName("Eheheh :)") Return File(fi.OpenRead, "audio/mpeg","Media File") 
} 

使可变公共

FileResult指数(字符串picPath)

FileInfo的网络连接=新的FileInfo(使用Server.Mappath (“〜/ Content/imgs /”+ picPath + “));

网址:文件/目录/ fillo_kargo.png

+0

谢谢你的建议。 – hncl