Dynamic image and Ajax in ASP.NET MVC
I'm trying to show a detail partialview using ajax and colorbox. It's working fine but only the first time. After that GetGraph is not run and the first image is displayed again. If I reload the entire page it's working one time again. The detailinfo is updating OK it's just the chartimage that's not working.
Somewhat related question
Here's what I have so far:
jQuery:<script type="text/javascript">
$(document).ready(function () {
$("a.details").click(function () {
var id = $(this).attr("href");
$.post('GetDetails', { id: id }, function (data) {
$.fn.colorbox({ open: true, html: data });
});
return false;
});
})
</script>
Contoller actions:
[Authorize(Roles = "Statistics")]
public ActionResult Get开发者_运维问答Details(string id)
{
var user = MemberShipRepository.GetUserInfo(User.Identity.Name);
var details=StatisticsService.GetSaleDetail(user.UserId, id);
var chart = StatisticsService.CreateChart(details.MontlySales);
TempData["Chart"] = chart;
ViewData.Model = details;
return View();
}
public ActionResult GetChart()
{
var file = TempData["Chart"] as byte[];
return File(file, "image/png");
}
Partial view:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<SaleDetail>"%>
<table>
<!--Code for displaying detailinfo-->
</table>
<div id="DetailsGraph">
<h3>
<%=Html.Encode(ResStrings.StatsticStrings.Statistic) %></h3>
<img src="GetChart" width="700" height="300" alt="Graph" />
</div>
Well for one thing you are calling the GetDetails action in you $.post instead of the GetChart action.
精彩评论