Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Olivia Philomena Moser 10 posts 91 karma points
    Feb 06, 2024 @ 09:58
    Olivia Philomena Moser
    0

    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.

  • Alex Skrypnyk 6175 posts 24186 karma points MVP 8x admin c-trib
    Feb 09, 2024 @ 16:27
    Alex Skrypnyk
    0

    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

  • Olivia Philomena Moser 10 posts 91 karma points
    Feb 22, 2024 @ 09:40
    Olivia Philomena Moser
    0

    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!

Please Sign in or register to post replies

Write your reply to:

Draft