ASP.NET MVC: RenderAction for creating an action

I have an action that returns an image:

    public void SensorData(int id, int width = 300, int height = 100)
    {
        using (var repo = new DataRepository())
        {
            var sensor = repo.GetSensor(id);
            if (sensor == null) return;

            var chart = new Chart(width, height);
            chart.AddSeries(name: "Values", 
                            chartType: "line", 
                            xValue: sensor.DataValues.Select(s => s.Date).ToList(),
                            yValues: sensor.DataValues.Select(s => s.Value).ToList());

            chart.Write();
        }
    }

This action looks great when I call it from the browser (for example, controller_name / SensorData / 6). The problem is that when I try to view it using Html.RenderAction, I get the following compilation exception on my view:

The best overloaded method match for "System.Web.WebPages.WebPageExecutingBase.Write (System.Web.WebPages.HelperResult)" has some invalid arguments.

This is the code that throws the exception:

@Html.RenderAction("SensorTypes", new { id = 6});

Any ideas on what could be causing this?

thank

+3
source share
2 answers

HTML. .

<img src='@Url.Action("SensorTypes", new { id = 6})'  />
+4

:

@{Html.RenderAction("SensorTypes", new { id = 6 });}

@Html.Action("SensorTypes", new { id = 6 })

WebForms:

<% Html.RenderAction("SensorTypes", new { id = 6 }); %>
<%= Html.Action("SensorTypes", new { id = 6 }) %>
+5

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


All Articles