2012-07-25 67 views
1

我有一个使用Url.Action填充图像src的JQuery日期选择器。ASP.NET MVC ActionResult未在IPad上显示图像

<script type="text/javascript"> 
     $(function() { 
      $('#datepicker').datepicker({ 
       inline: true, 
       altField: '#selecteddate', 
       altFormat: 'dd-mm-yy', 
       onSelect: function() { 
        var date = $('#datepicker').datepicker('option', 'dateFormat', 'yy-mm-dd'); 
        $('#diary img').attr(
         'src', 
         '<%= Url.Action("Image") %>/' + date.val().toString()); 
       } 
      }); 
     });   
    </script> 

图像是在存储器中的位图使用我的控制器上的以下动作转换为PNG

public class ImageResult : ActionResult 
{ 
    Image image; 

    public ImageResult(Image image) 
    { 
     this.image = image; 
    } 

    public override void ExecuteResult(ControllerContext context) 
    { 
     context.HttpContext.Response.Clear(); 
     context.HttpContext.Response.ContentType = "image/png"; 

     image.Save(context.HttpContext.Response.OutputStream, ImageFormat.Png);       
     image.Dispose(); 
    } 
} 

所述的图像显示细然而所以它示出了作为图像的src不具有延伸/ 2012-07-11如何添加扩展名.png?因为没有我相信它停止它显示在Ipad上。

+1

您是否使用该图片的默认路由模式网址是什么?请张贴在浏览器上呈现的路由和相应的URL。至少,您应该能够使用自定义路线显示.png扩展名。 – danludwig 2012-07-25 12:14:36

+0

是的,我使用默认的路由模式 - 图像出来如下非常确定我只需要在日期的末尾添加.png。谢谢 – 2012-07-25 15:33:31

回答

0

你可以重新创建一个具有.png扩展内置的一个新途径:

routes.MapRoute(
    "Image", // Route name 
    "tunnel/image/{id}.png", // URL with parameters 
    new { controller = "Tunnel", action = "Image" }    
); 

和更新您的JavaScript像这样:

'tunnel/image/' + date.val().toString() + '.png';