我有一个使用 Url.Action 填充图像 src 的 JQuery 日期选择器。
<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 上显示。