Asp.net mvc multi-parameter queries for dynamic images?

In webforms, we would do something like this to set up a handler for creating a dyanmic image:

<img src="/barchart.aspx?width=1024&height=768&chartId=50" >

Then, of course, we will write the code on the .aspx page to display the image using the parameters and write it back to the response.

I honestly don’t know how to configure / process such a request using MVC and how we will activate it (in general terms) from the view.

Any pointers or help are welcome in advance.

+3
source share
2 answers

If I understand the situation correctly:

public class ImageGeneratorController : Controller {
    public ActionResult BarChart(int width, int height, int chartId) {
        // ASP.NET MVC will map the request parameters to method arguments
    }
}

To create a link:

Url.Action("BarChart", "ImageGenerator", new {
    width = 1024,
    height = 768,
    chartId = 50
});

It will display:

/ImageGenerator/BarChart?width=1024&height=768&chartId=50
+5
source

. , FileResult :

public FileResult BarChart(int width, int height, int chartID) {
    //create the chart
    return new FileContentResult(byte[] fileContents, string contentType);
}

html:

<img src="/yourController/BarChart/1024/768/50">
+2

Source: https://habr.com/ru/post/1707263/


All Articles