Qwerz
Blazor: calling a function on submit
Please someone tell me if I'm approaching this the wrong way:
when a form is submitted I want to display a modal for which I have a function "ShowModal()". I attempted to call it at the end of the HandleSubmit function appointed to the form. However, the page reloads on submit...no modal is ever shown. Example below:
Now I can imagine this being a problem in future ventures extending the basic contact form, so I ask: how can I call a function in the chain triggered by a submit event (which reloads the page).
1 replies
Blazor Forms and Different Sessions
Hi all,
I'm working on a simple webpage (functioning as a homepage) with blazor (server). My current goal is to create a contact form at the bottom of the page, where customers can send a message to staff.
I created an EditForm using a model and used MailKit in the code fragment to send the message submitted by the EditForm via our mail server. This worked as expected until...
A co'worker told me this approach was not feasible for the following reason:
While one client visiting the website and submitting the form works, it does not work as intended when there are multiple clients accessing the site and editing the form:
E.g. if two clients connect to the website and fill out the form and then submit it simultaneously, the data submited is messed up and mixed between the two accessing sessions. How can this be? I though Blazor would handle these requests asynchronously. I was told the issue lies in the Datacontext being the same for every session and thus all clients editing the same instance of a static object (the EditForm).
What must I change to get the expected behaviour? Thanks in advance!
14 replies
✅ How do you handle countdowns of objects?
I have a List of Objects, each has an expiry date. I would like to display a countdown (e.g. 1 hour and 1 minute until expiry) in one of my views (WPF).
I'm unsure however, how to construct this in regards to timers. I calculate the time left by subtracting the current date from the date of expiration. If I do this in the object class and implement OnPropertyChanged I get a stackoverflow error, which is understandable because the subtraction would be calculated infinitely often. I also don't want to create a timer for every object because there could be quite a lot of those.
What is a better approach for this? I thought of creating a second collection that stores all the calculated values and is updated by a single timer, but I'm unsure how to implement this. I'd be grateful for your assistance!
33 replies
Adding items to an observable collection from 'outside' (MVVM)
Hi all,
I'm developing a desktop application in a small team of developers using WPF. I am responsible for the WPF part of the project while my coworkers are responsible for the core functionality.
We are all new to the MVVM approach, and I'm afraid that I have not grasped it properly despite me having thought that I did.
I'm going to simplify my problem a little for the sake of explaining it without too much detail.
I created a view with an items control. The items control has an ItemsSource binding to an observable collection in the corresponding ViewModel. The goal is to display events (errors, success messages, etc.) in this view, hence the observable collection is one of "messages".
The problem lies in adding events to the collection from across the program. The general structure of the project consists of multiple manager classes handling functions such as getting and setting data from a database, e.g. a "DatabaseManager". Ideally, I would have thought that in my ViewModel, I create a static function "NewEvent" which adds an event to the Observable collection. However, this isn't possible because the ViewModel and its collection are not static. I.e. : a function runs in the DatabaseManager and from there, a new event should be deployed and shown in the view via the observable collection.
What is the correct way to implement this? I assume I could make the collection static and reference the VM directly, but is that the correct way WPF wants me to take?
This is an example of a general problem I seem to be having with the MVVM methodology. I understand the View and ViewModel separation, however I'm utterly uncertain how to connect the UI Framework part with the actual functions in the backbone of any application. The vast majority of tutorials show how to bind a text box and a button to the extent that items are added to a list 'visually'. They never go into detail how to implement functions in the actual backend of an application.
Thanks a lot in Adv.
14 replies
✅ Selenium Vs. WebView
Hi,
Quick question: does WebView2 make Selenium obsolete? Assuming the goal is to create the automation of a headless browser.
I have no prior experience with WebView, but am contemplating whether it’s worth getting into and ditching Selenium. I’m not 100% sure though if it offers the exact same feature set.
Thanks I’m advance.
21 replies