I'm creating an asp.net mvc app that generates a qr code on a button click when the user inputs a string. The problem is the user input clears every time I press the button. I've tried adding onsubmit="return false" but then the qr code doesn't get generated.
C# Code: public ActionResult Index(string qrcode) { using (MemoryStream ms = new MemoryStream()) { QRCodeGenerator qrGenerator = new QRCodeGenerator(); QRCodeData qrCodeData = qrGenerator.CreateQrCode(qrcode, QRCodeGenerator.ECCLevel.Q); QRCode qrCode = new QRCode(qrCodeData); using (Bitmap bitMap = qrCode.GetGraphic(20)) { bitMap.Save(ms, ImageFormat.Png); ViewBag.QRCodeImage = "data:image/png;base64," + Convert.ToBase64String(ms.ToArray()); } } return View(); } HTML: <form asp-action="Index" asp-controller="Home"> Site ID:<input type="text" name="qrcode" id="site"> Device ID:<input type="text" name="device"> Validation ID:<input id="year"> <input type="submit" value="Generate" id="subButton"/> How can I make it so the user input is still there after the button click but the qr code is still generated?
https://stackoverflow.com/questions/66603550/prevent-textbox-reset-while-still-generating-qr-code-asp-net March 13, 2021 at 12:21AM
没有评论:
发表评论