JJConsulting / JJMasterData

.NET CRUD generator library with Bootstrap support to create dynamic forms at runtime from a data dictionary.
https://md.jjconsulting.tech/
GNU General Public License v3.0
166 stars 22 forks source link

replace constructor #261

Open MadsCastle7 opened 3 weeks ago

MadsCastle7 commented 3 weeks ago

I am trying to get a form displayed in a Blazor web site. I don't need a mobile version that you pointed out was a problem before. However, in Blazor I cannot instantiate the object in a constructor as Blazor will not allow this and gives an error when trying to add the class as a singleton in Program.cs

image

Is it therefore possible to do something like:

IComponentFactory c = new ComponentFactory();

As it stands it appears that the protection level on the class will not allow this.

gumbarros commented 2 weeks ago

Hello @MadsCastle7, Blazor until .NET 9 don't support constructor injection.

You can try using InjectAttribute.

Please send any info here if this is not what you meant.

MadsCastle7 commented 2 weeks ago

the above didn't work . so instead of trying to use JJMasterdata directly in Blazor, i've created an API project and added a route in there. The code below successfully returns the form

image

I have then added an HttpPost route to try and save the contents, however GetFormValuesAsync() is always empty. I'm guessing that i need a handle to the form id? Can you offer any advice?

image

gumbarros commented 2 weeks ago

the above didn't work . so instead of trying to use JJMasterdata directly in Blazor, i've created an API project and added a route in there. The code below successfully returns the form

image

I have then added an HttpPost route to try and save the contents, however GetFormValuesAsync() is always empty. I'm guessing that i need a handle to the form id? Can you offer any advice?

image

Can you share the complete snippet of your .razor or .cs file so I can repro?

MadsCastle7 commented 2 weeks ago

razor page image

razor c# image

gumbarros commented 2 weeks ago

You need to send the form values at your Post request, because without the form values the GetFormValuesAsync will not know what to send to you I think.

MadsCastle7 commented 2 weeks ago

How would i get the model populated in the PostAsync?

On another screen, I've amended the form returned and added some bind statements to it to bind it to a model , which then worked. But, how can I populate the model to send in the Post without manually changing the returned form?

image