Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace constructor #261

Open
MadsCastle7 opened this issue Aug 22, 2024 · 6 comments
Open

replace constructor #261

MadsCastle7 opened this issue Aug 22, 2024 · 6 comments

Comments

@MadsCastle7
Copy link

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
Copy link
Member

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
Copy link
Author

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
Copy link
Member

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
Copy link
Author

razor page
image

razor c#
image

@gumbarros
Copy link
Member

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
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants