-2

Barcode being a string passed from the controller and displayed on the view:

@shelfEdge.Barcode

How do I get this to display in barcode format, just a matter of downloading a barcode font and adding it to the class?

any ideas welcome

UPDATE Ive used the post in Free Barcode API for .NET from Andrei Schneider...

 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");

then in view @Model.BarcodeImage

but this throws 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>

and I have referenced system.drawing in project??

Community
  • 1
  • 1
John
  • 3,965
  • 21
  • 77
  • 163

2 Answers2

2

You need to generate the barcode as an image, and then render the image on the page as usual. See this free library:

http://barcoderender.codeplex.com/

Oscar
  • 13,594
  • 8
  • 47
  • 75
  • 1
    @John did you read he new error? It is another question -and one fundamental. Runs down to "what the heck is an assembly and why do I need to add it to references if I want to use it?" – TomTom Apr 11 '14 at 10:14
  • @John The error is self explanatory, simply add a reference to System.Drawing in your project and it will be gonne. – Oscar Apr 11 '14 at 11:12
0
@ViewBag.mostrar = "data:image/jpg;base64," +
 Convert.ToBase64String((byte[])model.BarcodeImage);

I hope than this help you

thor
  • 21,418
  • 31
  • 87
  • 173