Copied to clipboard

Flag this post as spam?

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


  • TempleClause 32 posts 248 karma points
    Feb 17, 2015 @ 23:58
    TempleClause
    0

    Surface Controllers URL, keep getting 404

    Hi I created the following SurfaceController:

     namespace NgakNgakBeach.SurfaceControllers
     {
        public class NgakNgakActionController : Umbraco.Web.Mvc.SurfaceController
        {
            [HttpPost]
            public ActionResult AjaxTest()
            {
                return Json("this works!");
            }
        }
    }
    

    According to the doc (https://our.umbraco.org/Documentation/Reference/Mvc/surface-controllers) I should be able to call this via: http://localhost:12429/umbraco/surface/NgakNgakAction/AjaxTest but I keep getting a 404.

    I also saw that there are APIControllers (https://our.umbraco.org/documentation/Reference/WebApi/).

    Which type should I use for fron end ajax calls?

    Thanks!

  • TempleClause 32 posts 248 karma points
    Feb 18, 2015 @ 00:02
    TempleClause
    100

    Whooops! Figured it out! Needed to change from [HttpPost] to [HttpGet].

    The question whether to use a SurfaceController or an APIController remains.

    Thanks

  • Nicholas Westby 2054 posts 7100 karma points c-trib
    Feb 18, 2015 @ 01:16
    Nicholas Westby
    1

    In general, use a SurfaceController when you need an UmbracoContext (the thing that tells you what page you are on). You might want that, for example, if there is a form on the page and you want to know what page the user posted the form from.

    Use an ApiController if you are calling the service from something external to the website (e.g., via an app). I believe in this case you don't have an UmbracoContext (which makes sense, since you aren't "on" a page).

  • TempleClause 32 posts 248 karma points
    Feb 18, 2015 @ 17:23
    TempleClause
    0

    Okay great, got it! Thanks

Please Sign in or register to post replies

Write your reply to:

Draft