如何將字節數組作為參數發送到 HTML.Action? (How to send byte array as paramater to HTML.Action?)


問題描述

如何將字節數組作為參數發送到 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" />
    }

但我得到了:

無效的匿名類型成員聲明。匿名類型成員必須使用成員分配、簡單名稱或成員訪問來聲明。

getImage 方法:

public FileContentResult getImage(byte[] bytes)
{
   return new FileContentResult(bytes, "image/jpeg");
}

我該如何解決這個問題?


參考解法

方法 1:

In an anonymous type you dont define the variable type byte[]. It works it out itself based on the type of m.Bytes

@foreach (var m in Model[0].HistoryValues)
{
    <img src="@Html.Action("getImage", "OverWatch", new { Mybytes= m.Bytes })" alt="Person Image" />
}

(by ThunD3eRCathalMF)

參考文件

  1. How to send byte array as paramater to HTML.Action? (CC BY‑SA 2.5/3.0/4.0)

#bytearray #filecontentresult #asp.net-mvc #C#






相關問題

更改創建 XML 閱讀器時使用的 XmlDictionaryReaderQuotas 對象的 MaxArrayLength 屬性 (Changing the MaxArrayLength property on the XmlDictionaryReaderQuotas object used when creating the XML reader)

將文件讀入 4 個字節的 ByteArrays (Read file into ByteArrays of 4 bytes)

使用套接字 (C#) 進行文件傳輸 - 接收到的文件不包含完整數據 (File transfer using sockets (C#) - received file doesn't contain full data)

將 Java 字節讀取器轉換為 InputStream (Converting a Java byte reader to an InputStream)

用 bigInteger 和其他方法重建字節數組 (Rebuild byte array with bigInteger and other method)

如何將字節數組作為參數發送到 HTML.Action? (How to send byte array as paramater to HTML.Action?)

如何將存儲在字節數組中的圖像加載到 WebView? (How to load an image stored in a byte array to WebView?)

我希望將畫布保存為 mySql blob 字段中的 blob (I am looking to save a canvas as a blob in mySql blob field)

將字節數組的部分轉換為整數值 (Converting sections of byte arrays to integer values)

從內存中釋放 jni 引用 (Freeing jni references from memory)

為什麼 JPGEncoded bytearray 從 AS3 發送到 AMFPHP 會導致圖像無效? (Why is JPGEncoded bytearray sent from AS3 to AMFPHP resulting in an invalid image?)

Java:字節到浮點數/整數 (Java: Bytes to floats / ints)







留言討論