2014-04-11 34 views
-2

条形码是由控制器通过并显示在视图中的字符串:如何产生鉴于条形码

@shelfEdge.Barcode 

我如何得到这个条形码格式显示,仅下载条形码字体的事并将其添加到课堂?

任何想法表示欢迎

UPDATE 伊夫使用后在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

但是,这将引发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项目??

+1

您需要使用第三方组件(ComponentOne的,阅读Aspose等) – Mahmoodvcs

+0

你可以尝试用syncfusion条码 – SivaRajini

+0

感谢您的回复球员,请参阅编辑....谁投了-1请解释你的理由? – John

回答

2

您需要生成条形码作为图像,然后像往常一样在页面上呈现图像。看到这个免费的图书馆:

http://barcoderender.codeplex.com/

+0

感谢您的回复,请参阅编辑 – John

+1

@John你读过他的新错误吗?这是另一个问题 - 一个根本。运行到“组件到底是什么,为什么我需要将它添加到引用中,如果我想使用它?” – TomTom

+0

@John错误是不言自明的,只需在项目中添加一个对System.Drawing的引用,它就会变成gonne。 – Oscar

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

我希望比这个帮助你