如何在视图中生成条形码

本文关键字:条形码 视图 | 更新日期: 2023-09-27 17:57:56

条形码是从控制器传递并显示在视图上的字符串:

@shelfEdge.Barcode

如何以条形码格式显示,只需下载条形码字体并将其添加到类中即可?

任何想法欢迎

更新我在免费条形码API中使用过这篇文章。NET。。。

 BarcodeLib.Barcode barcode = new BarcodeLib.Barcode()
    {
        IncludeLabel = true,
        Alignment = AlignmentPositions.CENTER,
        Width = 300,
        Height = 100,
        RotateFlipType = RotateFlipType.RotateNoneFlipNone,
        BackColor = Color.White,
        ForeColor = Color.Black,
    };
    model.BarcodeImage = barcode.Encode(TYPE.CODE128B, "123456789");

则在视图CCD_ 1 中

但这抛出了errro:

    Compiler Error Message: CS0012: The type 'System.Drawing.Image' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
Source Error:


Line 54:                             </td>
Line 55:                             <td width="30%">
Line 56:                                 @Model.BarcodeImage
Line 57:                             </td>
Line 58:                         </tr>

我在项目中引用了system.drawing??

如何在视图中生成条形码

您需要将条形码生成为图像,然后像往常一样在页面上呈现图像。查看此免费库:

http://barcoderender.codeplex.com/

@ViewBag.mostrar = "data:image/jpg;base64," +
 Convert.ToBase64String((byte[])model.BarcodeImage);

我希望这能帮助你