cs12dotnet8 icon indicating copy to clipboard operation
cs12dotnet8 copied to clipboard

ch15-blazor-wasm.md missing formname

Open LesF opened this issue 1 year ago • 6 comments

Not sure if I have missed a step, but when I followed the online blazor-wasm chapter, posting create or update forms gives the error:

The POST request does not specify which form is being submitted. To fix this, ensure <form> elements have a @formname attribute with any unique value, or pass a FormName parameter if using <EditForm>.

So I added a parameter to CustomerDetail.razor to set formname. After that, the browser console shows errors when loading the customer list and clicking the link to edit a row. The dotnot resources loaded message shows, then it gives:

Error: One or more errors occurred. (Root component type 'Northwind.Blazor.Components.Pages.EditCustomer' could not be found in the assembly 'Northwind.Blazor'.)
    at Jn (marshal-to-js.ts:349:18)
    at Tl (marshal-to-js.ts:306:28)
   ...etc...

The edit form displays, I assume it gets it from the server. If I make a change and submit, no changes are saved and there are no errors shown. If I open the create form and submit I get:

InvalidOperationException: Unable to track an entity of type 'Customer' because its primary key property 'CustomerId' is null.

I can provide the errors from the browser console if needed, if there isn't an obvious mistake I have made configuring the project for wasm.

LesF avatar May 31 '24 00:05 LesF

I'm also facing the same issue, I've followed the steps from last chapter in the book and the WASM online chapter here in github but the Wasm assembly is not finding the Interactive pages and failing with this error:

Error: One or more errors occurred. (Root component type 'Northwind.Blazor.Components.Pages.CreateCustomer' could not be found in the assembly 'Northwind.Blazor'.)
    at Jn (marshal-to-js.ts:349:18)
    at xl (marshal-to-js.ts:306:28)
    at 00b217ca:0x1fa8f
    at 00b217ca:0x1bf5a
    at 00b217ca:0xf141
    at 00b217ca:0x1e7a9
    at 00b217ca:0x1ef9f
    at 00b217ca:0xcfbb
    at 00b217ca:0x4412f
    at e.<computed> (cwraps.ts:338:24)

I've searched in google without any luck on how to fix this, this is the repo with the code https://github.com/batusai513/dotnet-learn/tree/main/cs12dotnet8/PracticalApps/Northwind.Blazor

batusai513 avatar Jun 27 '24 06:06 batusai513

I'm not having much luck with this either. I added the FormName attribute to the EditForm in CustomerDetail.razor (the FormName is a requirement for EditForm, and @formname is required for a plain html form).

Deleting a customer is working, but editing or creating a customer does not work. When trying to create a customer, I am getting client-side validation errors for the customerId and customername.

pmarangoni avatar Jun 28 '24 17:06 pmarangoni

I apologise for not getting to this sooner. I have been busy working on final drafts for my next book, Tools and Skills for .NET8. This weekend I should be (finally!) done with that, so I'll then have time to properly look at this issue. I've already gone through the print book Chapter 15 and fixed some minor errata. Next, I'll review the online client-side section. Thank you for your patience.

markjprice avatar Jun 29 '24 07:06 markjprice

I'm sure we all appreciate your help with this. Thanks!

pmarangoni avatar Jun 29 '24 16:06 pmarangoni

Still waiting for some action on this a month later.

pmarangoni avatar Jul 29 '24 18:07 pmarangoni

I have updated the online section with new instructions and made the same changes to the PracticalApps solution code in the Northwind.WebApi, Northwind.Blazor, and Northwind.Blazor.Wasm projects. This should fix the problems. https://github.com/markjprice/cs12dotnet8/blob/main/docs/ch15-blazor-wasm.md

markjprice avatar Aug 06 '24 12:08 markjprice