C
C#9mo ago
XD

❔ Form with put or delete method

Since I can't add a method="put" or "delete" to my forms, how else can I add a put or delete method to my forms? I want to execute a function from the controller after submitting the form that will update/delete. I'm not using actions because this is an SPA, and I can't do something like, specifying a post method in the form and then, in the .cshtmlcs write code for a PUT inside an OnPost function because it's an MVC app
6 Replies
x0rld
x0rld9mo ago
you can just use fetch to submit with the http method you want
XD
XD9mo ago
yeah i did it but, now I want to add validation and I was thinking of doing it with a Model, to which I would add Data Annotations i was thinking that data annotations would be simpler and better than writing JS for the validation
x0rld
x0rld9mo ago
you can use something like fluent validator I don't event know if data annotation works for api
XD
XD9mo ago
ill research on it, seems good thank you man or woman idk
Dark1
Dark19mo ago
I assume youre using a API for the SPA. FluentValidation (NuGet) can be used for both sides: 1. Register your validators in your services: builder.Services.AddValidatorsFromAssemblyContaining<CreateClientValidation>(); 2. Now you can retrieve you validators with DI: public CreateClientHandler(CreateClientValidation validator) 3. Validate with your validator: var validationResult = await validator.ValidateAsync(request, cancellationToken); For deleting, you create a http request with the DELETE httpmethod and send it to the url. Use Swagger/Postman to test your endpoints.
Accord
Accord9mo 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
More Posts