0

I'm using BarcodeLib. How can i use like this in controller ? I was using that in aspx with IHttpHandler but how to use in controller ?

<img src="/StokBarkod/Barrr?barcodeText=Hello" /> 

/////

public ActionResult Barcode(string barcodeText) { BarcodeLib.Barcode barcode = new BarcodeLib.Barcode { IncludeLabel = false, Alignment = BarcodeLib.AlignmentPositions.CENTER, LabelPosition = LabelPositions.BOTTOMCENTER, RotateFlipType = RotateFlipType.RotateNoneFlipNone, //LabelFont = new Font("Arial", 18 * 1), Width = 135, Height = 22, BackColor = System.Drawing.Color.White, ForeColor = System.Drawing.Color.Black }; //var yeniKod = barcodeText.Replace("//", "%"); System.Drawing.Image img = barcode.Encode(BarcodeLib.TYPE.CODE128, barcodeText); Byte[] bytdizi = new Byte[-1 + 1]; bytdizi = (Byte[])imageToByteArray(img); System.IO.Stream ms = new System.IO.MemoryStream(bytdizi); byte[] buffer = new byte[4096]; int byteSeq = ms.Read(buffer, 0, 4096); HttpContext.Current.Response.ContentType = "image/jpeg"; while (byteSeq > 0) { HttpContext.Current.Response.OutputStream.Write(buffer, 0, byteSeq); byteSeq = ms.Read(buffer, 0, 4096); } } 

Help me please ?

2
  • Shouldn't you just use the FileResult? The last half of this code seems to overcomplicate simple things. Commented Dec 12, 2015 at 16:55
  • You should never directly write to the response in an action method. You should always be returning some object that inherits from ActionResult. Commented Dec 12, 2015 at 16:56

1 Answer 1

1

use JsBarcode. its easily generate barcode in JS.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.