开发者

Dynamic image and Ajax in ASP.NET MVC

开发者 https://www.devze.com 2023-01-10 23:51 出处:网络
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 ent

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消