I am experimenting with Nic's method of streaming images as FileResult from controllers. CodeProject article.
I thought I take it a step further and have an image get updated via jQuery.
I have tried all sorts of ways but can't get the image to show. In this current state I am seeing all the characters of the PNG, I think it is sending the binary data.
Anyone have any ideas on how to do this?
Partial View
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
<img src="/Home/GetHistoryChart" alt="My Chart" id="imgHistoryChart" />
Page
<input id="begindate" type="text" readonly="readonly" style="width:70px;" />
<input id="enddate" type="text" readonly="readonly" style="width:70px;" />
<input type="submit" value="Refresh" id="refreshHistory" />
<div type="text" id="datepicker"></div>
<div id="theImageHistory">
<% Html.RenderPartial("~/Views/Home/Charts/HistoryImg.ascx"); %></div>
<%--Gets the partial view shown above--%>
</div>
<script type="text/javascript">
$(document).ready(function() {
$("#refreshHistory").click(function() {
var fromDate = $("#begindate").val();
var toDate = $("#enddate").val();
RefreshImage(fromDate, toDate);
});
});
function RefreshImage(from, to) {
$('div#theImageHistory').load('/Home/GetHistoryChart', { fromDate: '8/1/2009', toDate : '8/24/2009' },
function(html) {
//$('div#theImageHistory')[0].value = html;
alert('Do I get here');
});
}
</script>
Controller
public FileResult GetHistoryChart(string? fromDate, string? toDate)
{
// code...
System.IO.MemoryStream imageStream = new System.IO.MemoryStream();
Chart1.SaveImage(imageStream, ChartImageFormat.Png);
return new FileResult("Yo.png", "image/png", imageStream.ToArray());
}