Welcome to deBUG.to Community where you can ask questions and receive answers from Microsoft MVPs and other experts in our community.
1 like 0 dislike
905 views
in .Net Framework by 39 42 54
edited by

I am working on an MVC solutions and I want to generate QR code that contain more details about someone and save it's data automatically when scan QR , How can I do that in MVC?

 


1 Answer

1 like 0 dislike
by 39 42 54
edited by
 
Best answer

QR Code Generation in MVC

To generate QR code that contain more details about someone and save it's data automatically when scan QR, you should follow the below steps in details:

  1. You should create GeneratevCard that accept parameters such as : FirstName ,LastName,MobileNo ,Email and OrganizationName and return byte[]

      public static byte[] GeneratevCard(string FirstName, string LastName, string MobileNo, string Email,string OrganizationName)
          {
                 StringBuilder vCardBuilder = new StringBuilder();
    
                 vCardBuilder.AppendLine("BEGIN:VCARD");
                 vCardBuilder.AppendLine("VERSION:3.0");
                 vCardBuilder.AppendLine($"FN:{FirstName} {LastName}");
                 vCardBuilder.AppendLine($"N:{LastName};{FirstName};;;");
                 vCardBuilder.AppendLine($"TEL;TYPE=CELL:{MobileNo}");
                 vCardBuilder.AppendLine($"EMAIL:{Email}");
                 vCardBuilder.AppendLine($"ORG:{OrganizationName}");
                 vCardBuilder.AppendLine("END:VCARD");
             return GenerateQR(vCardBuilder.ToString());
      }
    
  2. Call method in your controller

        var QR = QrGenerator.GeneratevCard("Moahamed", "Elsakhawy", "0096654039XXXX", "melsakhawyXX@gmail.com", "CompanySample");
        ViewBag.QrCodeBase64 = Convert.ToBase64String(QR);
    
  3. Call ViewBag with name QrCodeBase64 in frontend

     <div class="text-center">
         <h5>@Resources.Labels.MobileInfo</h5>
         <img id='base64image'
                src='data:image/jpeg;base64, @ViewBag.QrCodeBase64' width="150" class="img-thumbnail" />
     </div>
    
  4. Scan QR Code using Mobile Camera .
    QR Code in MVC

  5. Great, the QR code has been working properly.
    Generate QR Code in MVC

If you don’t ask, the answer is always NO!
...