-2

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

@shelfEdge.Barcode

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

欢迎任何想法

更新 我使用了Andrei Schneider的Free Barcode API for .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");

然后在视图中@Model.BarcodeImage

但这会引发错误:

    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??

4

2 回答 2

2

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

http://barcoderender.codeplex.com/

于 2014-04-11T09:34:05.053 回答
0
@ViewBag.mostrar = "data:image/jpg;base64," +
 Convert.ToBase64String((byte[])model.BarcodeImage);

我希望比这对你有所帮助

于 2016-12-19T22:45:58.940 回答