❔ Using razor pages to generate a list and send to code file

So I have a table called GenericEvents, and I have various activities that use this generic event to do scheduling on a calendar. The generic events are popualted using model binding when an event is create, and users populate date/time/ other info. With the standard CRUD pages that scaffolding pumps out, I can setup one genericEvent using the provided form, but what I'd like to do is be able to generate a List<genericEvent> so that one activity can be bound to multiple generic events (recurring). is there a way to model bind a List<T> of POCO objects that's driven by input from the view? For example, I'd like a button that would add a new generic event to the page model, and a UI element to set the values for that GenericEvent, then have the submit button send that List<GenericEvent> to the code behind file to be added to the db. Any general pattern I could follow to accomplish this easily without looping in react or something? I'd like to be able to create multiple generic events (like in this image) at runtime, is there a way to dynamically create page elements like these or is this locked to server-side functionality?
25 Replies
EntireTeamIsBabies
Orightcha, Let me read this ( fair headsup, I am learning blazor myself so this might get a bit bumpy) I know this is doable, because you're requesting nothing outlandish I just don't know from top of my head how this is done. It takes a wee bit of googling for me, if you want to wait for another helper , that's ok. What is your timeframe for solving this?
og.angrytaco
og.angrytacoOP2y ago
haha I was hoping to get it figured out today this isnt the only place im looking
EntireTeamIsBabies
If you place it in some place and use another account to give the ABSOLUTE wrong answer, people will jump on it to correct that answer, that one still works.
og.angrytaco
og.angrytacoOP2y ago
and yeah I did a lot of googling, they all seem to be intent on doing this in reverse order, generating an empty list and letting the ui populate that, rendering out using a for loop but IDK how many generic events they will need so they need to add them at create-time yeah this seems like it should be dead simple with blazor but alas im stuck
EntireTeamIsBabies
brb with some coffee and I will write some things down. that are crucial for your fix. can you hover over Generic events and tell me what error it gives?
og.angrytaco
og.angrytacoOP2y ago
oh its becasue I changed it to a LIST<GenericEvent> in the model and this is an individual Generic event its just in the middle of implementation lol it would be fixed if I added a [0]
og.angrytaco
og.angrytacoOP2y ago
going to try to see if this will do what I want it does seem to be based on a for loop so I'm a little worried its not going to behave clientside the way I think it will
EntireTeamIsBabies
What is your current hosting model?
og.angrytaco
og.angrytacoOP2y ago
IIS express LOL we aren't deployed to prod yet. Still in dev probably going to host it in azure tho
EntireTeamIsBabies
yeah I was wondering about the type of blazor, Server or WASM I have to dissapoint you at this point I am Mostly familiar with one-way-binding.
og.angrytaco
og.angrytacoOP2y ago
dang
EntireTeamIsBabies
How to do data binding on dynamic form In Blazor ?
Hi All, I have requirement to create the tabular template entry form, I am generating the form dynamically using look.  But whenever i m giving inp...
og.angrytaco
og.angrytacoOP2y ago
I'm not sure, I'll read through it. Got work starting soon
EntireTeamIsBabies
Yeah well, I'm working lists here too. I will be on standby for this, because I need to know this ruckus as well.
og.angrytaco
og.angrytacoOP2y ago
@MAR'🥚EntireTeamIsBabies! I may have found it
og.angrytaco
og.angrytacoOP2y ago
Stack Overflow
MVC Razor create list of objects to submit
I am an experienced .NET C# Software Developer, however only a few months ago i started worked with MVC Razor (MVC 5). I have a small situation that i couldn't find any answer to on the net(after...
EntireTeamIsBabies
OH! MVC! Wasn't even thinking about that
og.angrytaco
og.angrytacoOP2y ago
yeah IDK how mixing that into my razor page will wo0rk but it might be a solution
EntireTeamIsBabies
I was just reading 2 way binding like so: <input @bind="dataInput" /> The two-way binding in Blazor is achieved using the @bind keyword, which is typically used as an attribute. But yeah Cheers on you topman.
og.angrytaco
og.angrytacoOP2y ago
I mean its still not a razor solution so it might not map over 1:1
EntireTeamIsBabies
but your case is quite domainspecific. I hope it works, I will remain on standby in case it goes sideways. No response has been made since Last correspondence, I have been on Standby since 14:59, We can regard this case as closed. Thank you for trusting me to look over this case. Happy trails.
og.angrytaco
og.angrytacoOP2y ago
I mean I didn't a tually get a solution and would appreciate if other people more familiar with razor pages could still take a look Of course you didn't get a response I went to work lol
EntireTeamIsBabies
Do you wish to Reopen the Case?
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server