C
C#•2mo ago
Zoli

Passing data to a details page dilemma

Hi everyone 👋 I’ve got a small architectural dilemma and would love your input. Let’s say I have a list of item view models, and each one wraps its own model (e.g., ItemViewModel → Model). When I navigate from the list to a details page, what’s considered the better practice? Option A: Pass only the ID of the model OR Option B: Pass the entire ItemViewModel directly. ✅ Passing ID feels cleaner and safer (especially for deep linking, state restore, or lazy loading, but it means I would need to fetch and rebuild the vm again). 🤔 Passing the full ViewModel is convenient and avoids another lookup, but it couples pages more tightly. Would you ever pass a full ViewModel between pages, or do you always resolve it from an ID?
5 Replies
ティナ
ティナ•2mo ago
based on my experience, passing the whole vm is much better because you sometime need the reference to the parent
Zoli
ZoliOP•2mo ago
For both case when showing Details page and Edit? For me now for Details I pass the whole ItemViewModel and for Edit I pass the id and load from db.
ティナ
ティナ•2mo ago
you can refresh the vm when you press edit
Angius
Angius•2mo ago
How would you pass the whole VM? We're talking a Blazor SPA here?
Zoli
ZoliOP•2mo ago
You are right I was not clear its maily on Maui could work on WPF too (I just add the tag as Maui)

Did you find this page helpful?