Can I create all CRUD Operations in a Surface Controller?
So I was wondering if it is possible to use a Surface Controller for all crud operations (Umbraco V10). I know that I can create a Post method, but is it possible to add a Delete or Patch method? I tried to add a method like this:
public class DeleteController : SurfaceController {
[HttpDelete]
public IActionResult Delete()
{
...
}
}
but I only receive an 405 error telling me that the method is not allowed.
If I change the [HttpDelet] to [HttpPost] the method works, but I think that is semantically not correct.
And am I correct in saying that it is not common to have multiple methods in one Surface Controller? So I would have to create a Controller for each method.
SurfaceController are more like for interact with the front-end rendering of an Umbraco page. They can be used for rendering MVC child actions and for handling form data submissions. Surface controllers are auto-routed, meaning that you don't have to add/create your own routes for these controllers to work - From docs
I need to create a form to add and edit content, so I would use the Surface Controller to submit a form. But if I edit content, it would be a patch and not a post method. That's why I was wondering if I could use the Surface Controller for all CRUD operations.
I wanted to use the Surface Controller because I think it's a cleaner way than using the Umbraco API Controller.
Can I create all CRUD Operations in a Surface Controller?
So I was wondering if it is possible to use a Surface Controller for all crud operations (Umbraco V10). I know that I can create a Post method, but is it possible to add a Delete or Patch method? I tried to add a method like this:
but I only receive an 405 error telling me that the method is not allowed. If I change the [HttpDelet] to [HttpPost] the method works, but I think that is semantically not correct.
And am I correct in saying that it is not common to have multiple methods in one Surface Controller? So I would have to create a Controller for each method.
Hi Olivia
Can you try using api controllers https://docs.umbraco.com/umbraco-cms/reference/routing/umbraco-api-controllers ?
SurfaceController are more like for interact with the front-end rendering of an Umbraco page. They can be used for rendering MVC child actions and for handling form data submissions. Surface controllers are auto-routed, meaning that you don't have to add/create your own routes for these controllers to work - From docs
Thanks,
Alex
Hi Alex
I need to create a form to add and edit content, so I would use the Surface Controller to submit a form. But if I edit content, it would be a patch and not a post method. That's why I was wondering if I could use the Surface Controller for all CRUD operations. I wanted to use the Surface Controller because I think it's a cleaner way than using the Umbraco API Controller.
Thank you!
is working on a reply...