Generate and Display Barcode Image in ASP.NET MVC

Barcodes are essential for conveying product information in a machine-readable format, utilizing numbers and parallel lines. In this comprehensive guide, you’ll discover how to dynamically generate and display various types of barcodes in your ASP.NET MVC application, including popular formats such as Data Matrix, Aztec, and Code 128. By the end of this tutorial, you will have a fully functional ASP.NET MVC Barcode Generator ready for your projects. Let’s dive in!

Table of Contents

  1. Features of ASP.NET MVC Barcode Generator
  2. C# API to Generate Barcode in ASP.NET MVC
  3. Steps to Generate and Display Barcode Image
  4. Demo ASP.NET MVC Barcode Generator
  5. Download ASP.NET MVC Barcode Generator Source Code
  6. Get a Free License
  7. Conclusion
  8. See Also

Features of ASP.NET MVC Barcode Generator

The ASP.NET MVC Barcode Generator boasts a range of impressive features:

  1. Support for Various Barcode Symbologies:

    • Code 128
    • Code 11
    • Code 39
    • QR Code
    • Data Matrix
    • EAN 13
    • EAN 8
    • ITF 14
    • PDF 417
  2. Image Format Options:

    • PNG
    • JPEG
    • BMP
    • EMF
    • SVG
  3. Preview Functionality: View the generated barcode image before saving it.

  4. Download Capability: Easily save the generated barcode image to your local disk.

C# API to Generate Barcode in ASP.NET MVC

To create barcode images for display in your ASP.NET MVC application, we’ll utilize the Aspose.BarCode for .NET API. This powerful API facilitates the generation and recognition of a wide array of barcode types. You can either download the DLL or install it via NuGet using the following command:

PM> Install-Package Aspose.BarCode

Steps to Generate and Display Barcode Image in ASP.NET MVC

Follow these steps to generate and display a barcode image in your ASP.NET MVC application:

  1. Create a New Project: Select the ASP.NET Web Application (.NET Framework) project template.

    Select project template
  2. Select MVC: In the Create a new ASP.NET Web Application dialog, choose MVC and click Create.

    Select MVC
  3. Install Aspose.BarCode for .NET: Open the NuGet Package Manager and install the Aspose.BarCode for .NET package.

    Install Aspose.BarCode for .NET
  4. Create an Images Folder: Add a new folder named Images to store the generated barcode images.

    Create Images folder
  5. Create a Barcode Model: In the Models folder, create a model named Barcode to hold barcode information.

  6. Add Barcode Symbology Enumeration: Create an enumeration to list supported barcode symbologies in the Barcode.cs file.

  7. Add Image Format Enumeration: Similarly, add an enumeration for supported image formats.

  8. Modify the Index View: Open the Views/Home/index.cshtml file and replace its content with the provided script.

  9. Update HomeController: In the HomeController class, add a new action result to handle the post request.

  10. Add Image Download Action: Implement a new action result in the HomeController to manage image download requests.

  11. Run the Application: Finally, execute your application to see your barcode generator in action.

Demo ASP.NET MVC Barcode Generator

Here’s a demonstration of the ASP.NET MVC Barcode Generator application we have just built:

Demo ASP.NET MVC Barcode Generator

Demo ASP.NET MVC Barcode Generator

Download ASP.NET MVC Barcode Generator Source Code

You can download the complete source code for the ASP.NET MVC Barcode Generator application from GitHub.

Get a Free License

To explore the library without any evaluation limitations, you can get a free temporary license.

Conclusion

In this article, we explored how to generate and display a barcode image in an ASP.NET MVC application. We also learned how to download the generated barcode image programmatically. For further information, refer to the Aspose.BarCode for .NET API documentation. If you have any questions or need assistance, feel free to reach out on the Aspose forum.

See Also

This tutorial serves as a comprehensive guide for ASP.NET MVC barcode generation, allowing you to create barcode images in ASP.NET MVC using C# and display barcodes in ASP.NET MVC views effectively. Whether you are implementing dynamic barcode generation in your ASP.NET MVC application or looking for the best barcode library for ASP.NET MVC, this guide provides a solid foundation for your barcode generation needs.