Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6638117
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:23:47+00:00 2026-05-25T23:23:47+00:00

I’m using the FileStreamResult (or FileResult) method to display a chart on a razor

  • 0

I’m using the FileStreamResult (or FileResult) method to display a chart on a razor view page (from a Controller action) and this works as expected.

However, I’m wondering if it’s possible to display the chart ONLY when an html element is clicked.

e.g. Click on an element, display chart in modal pop-up.

I can get a modal to display using Jquery…but ONLY if I have already loaded the chart into a div.

I’d like to have the page load without the chart (for performance reasons), and then only generate/load the chart when the is clicked.

I guess I need an Ajax call of somekind…but I’m a little stuck as to how to proceed and googling didn’t return anything useful (just lightbox for photos)

Pseudo Code:

HTML:

<img src='small chart icon.jpg' alt='click me to see chart' id='showchart'/>
<div>
    rest of page goes here...
</div>

C#:

public FileStreamResult GetChart(){
    //generate any chart
    return FileStreamResult(newchartstream, "image/png");
}

JS:

<script>
$(document).ready(function(){
    $('#showchart').click(function(){
        //make ajax call to generate chart
        //show in modal with "close" button
        //OR
        //open a new page as a modal?
    });
});
</script>

EDIT

Clarification:

Controller generates a ViewModel (from an EF4 model) which contains the results of lots of calculations, and some “summary” rows (totals, averages etc)

View displays the results (ViewModel) as tables.

Requirement:

Click on one of the summary rows, opens modal window displaying a chart for that summary row.

Would like to avoid sendind the parameters for the ViewModel and re-generating it from scratch (doing all the calcs again etc) for two reasons

1) The figures in the back-end db may have changed…so the chart doesn’t reflect whats being shown in the tables.

2) It takes time to do the calcs!

I’d also like to ONLY generate the chart if the row is clicked, as opposed to loading the chart always and hide() show() with jquery.

I’ve thought about an ajax call, but unsure about how to return an image, or how to open a new page.

Can’t see a way to pass a complex model in the Url.Action() method.

Think caching may be the best option, and have the click method call “old fashioned” javascript for a new window, passing over the parameters to get the object from cache?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T23:23:48+00:00Added an answer on May 25, 2026 at 11:23 pm

    You have many ways to do that, but here is what I would do.

    1/ Create an action which returns a tag with the good src (assuming that your controller’s name is ChartsController).

        public ActionResult GetImage(int chartId = 0)
        {
            var image = @"<img id='chart' src='" + Url.Action("GetChart", new {controller = "Charts", chartId = chartId}) + @"'/>";
            return this.Content(image);
        }
    

    2/ I assume that, in your view, you have a div somewhere which contains your modal’s content (like jQuery-ui would do) with an img inside, for the chart.

    <div id="modal-div">
        <div id="chart-div"></div>
    </div>
    

    3/ For every row, you have to create an Ajax link who will call your “GetImage” action and replace “chart-div” with your . You can specify a “OnBegin” Javascript function, this is where you will put your code to launch the modal.

    @Ajax.ActionLink("Show me the chart!", "GetImage", "User", new { chartId = @Model.Rows[i]}, new AjaxOptions()
                                                                                            {
                                                                                                HttpMethod="GET",
                                                                                                OnBegin = "showModalWindow",
                                                                                                UpdateTargetId="modal-div",
                                                                                                InsertionMode = InsertionMode.Replace
                                                                                            });
    

    Everytime you will click on an Ajax link, the modal will be launched and the inside will be replaced (in fact, all the content of the modal will be replaced).
    Don’t forget to include “Scripts/jquery.unobtrusive-ajax.js” and “Scripts/jquery.validate.unobtrusive.js” for the Ajax links to work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;
Does anyone know how can I replace this 2 symbol below from the string
I'm making a simple page using Google Maps API 3. My first. One marker
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.