Updating bound property on device input event
Hello! I have been slowly learning ASP.Net Core on my own at my internship, and have recently gotten stuck with this issue:
I have a razor page with a single bound string property. When the pages constructor is called, i connect a Zebra Scanner device to it with the CoreScanner SDK provided by Zebra for their products. I then bind one of the pages member-functions as a callback to be called for when the scanner scans a barcode. When i run the page in debug-mode and set a breakpoint in the callback-function (OnBarcodeScanned) it successfully breaks within the function, and i can set the bound string property to whatever string the callback returns. However, after the callback is called the displayed string on the page is not changed. I have not been able to figure out the solution to this problem, and i'm not sure where to start. One thought i've had is that since no "POST" action is called upon callback, the page does not "know" to update itself. I've figured that maybe i need to somehow move the scanner-callback logic to "client-side", and have that push a "POST" to the page so it can be updated. I've also looked a bit at using AJAX for this. The problem here is that since i'm self-taught and noone where i intern can code i could really use a second opinion to clear up any misconceptions i might have.
Here is some sample code: InternalReview.cshtml:
@page @model QModulePrototype.Pages.InternalReviewModel @{ ViewData["Title"] = "InternalReview"; } <body> @Html.DisplayText(Model.ScannedXML) @Model.ScannedXML; </body>
InternalReview.cshtml.cs:
public class InternalReviewModel : PageModel { private readonly ScanningContext _scanningContext; [BindProperty] public string ScannedXML { get; set; } public InternalReviewModel(ScanningContext scanningContext) { ScannedXML = "XML GOES HERE\n"; _scanningContext = scanningContext; _scanningContext.Open(); // Initialize connection _scanningContext.GetScanners(); // Find scanners _scanningContext.SubscribeBarcodeEvent(OnBarcodeEvent); } public IActionResult OnGet() { return Page(); } private void OnBarcodeEvent(short EventType, ref string pScanData) { ScannedXML = "Scanned XML: " + pScanData; } }
0 comments:
Post a Comment