如何将字节数组作为参数发送到 HTML.Action?
How to send byte array as paramater to HTML.Action?
我今天一直在处理图表,我想我终于找到了一种方法让这一切都起作用,但我遇到了一个我不知道如何解决的问题。
在我的控制器中创建我的图表:
foreach (var m in model[0].HistoryValues)
{
var chart = new Chart(width: 300, height: 200)
.AddSeries(
chartType: "bar",
xValue: new[] { "Server", "Db", "Tickets" },
yValues: new[] { m.ServerPerformance, m.Databaseperformance, m.SoldTicketsLastUpdate })
.GetBytes("png");
m.Bytes = chart;
//m.ChartFile = File(chart, "image/bytes");
};
现在我想在视图中将它们显示为图像:
@foreach (var m in Model[0].HistoryValues)
{
<img src="@Html.Action("getImage", "OverWatch", new { byte[] Mybytes= m.Bytes })" alt="Person Image" />
}
但我得到:
Invalid anonymous type member declarator. Anonymous type members must
be declared with a member assignment, simple name or member access.
getImage 方法:
public FileContentResult getImage(byte[] bytes)
{
return new FileContentResult(bytes, "image/jpeg");
}
我该如何解决这个问题?
在匿名类型中,您不定义变量类型 byte[]。它根据 m.Bytes
的类型自行计算
@foreach (var m in Model[0].HistoryValues)
{
<img src="@Html.Action("getImage", "OverWatch", new { Mybytes= m.Bytes })" alt="Person Image" />
}
我今天一直在处理图表,我想我终于找到了一种方法让这一切都起作用,但我遇到了一个我不知道如何解决的问题。
在我的控制器中创建我的图表:
foreach (var m in model[0].HistoryValues)
{
var chart = new Chart(width: 300, height: 200)
.AddSeries(
chartType: "bar",
xValue: new[] { "Server", "Db", "Tickets" },
yValues: new[] { m.ServerPerformance, m.Databaseperformance, m.SoldTicketsLastUpdate })
.GetBytes("png");
m.Bytes = chart;
//m.ChartFile = File(chart, "image/bytes");
};
现在我想在视图中将它们显示为图像:
@foreach (var m in Model[0].HistoryValues)
{
<img src="@Html.Action("getImage", "OverWatch", new { byte[] Mybytes= m.Bytes })" alt="Person Image" />
}
但我得到:
Invalid anonymous type member declarator. Anonymous type members must be declared with a member assignment, simple name or member access.
getImage 方法:
public FileContentResult getImage(byte[] bytes)
{
return new FileContentResult(bytes, "image/jpeg");
}
我该如何解决这个问题?
在匿名类型中,您不定义变量类型 byte[]。它根据 m.Bytes
的类型自行计算@foreach (var m in Model[0].HistoryValues)
{
<img src="@Html.Action("getImage", "OverWatch", new { Mybytes= m.Bytes })" alt="Person Image" />
}