Copied to clipboard

Flag this post as spam?

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


  • Thomas Won Nyheim 33 posts 145 karma points
    Jan 10, 2018 @ 13:30
    Thomas Won Nyheim
    0

    Surface Controllers and routing, 404

    I have this code for the sruface controller:

      namespace Project.Web.Controllers.Surface
      {
       public class UserProfileSurfaceController : SurfaceController
       {
          [HttpPost]
          public ActionResult TestAction()
          {
              return Content("Testcode");
          }
        }
      }
    

    I'm trying to access this through the url http://localhost:51192/umbraco/Surface/UserProfileSurface/TestAction But get returned with a 404 page. Shouldn't it be possible to access the surface controller this way?

  • suman 30 posts 101 karma points
    Jan 10, 2018 @ 13:55
    suman
    0

    Hi Thomas,

    You have to call like this "http://localhost:51192/UserProfileSurface/TestAction". When you want to call Action method from Ajax then you have to call with "/umbraco/Surface/UserProfileSurface/TestAction"

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    Jan 11, 2018 @ 09:04
    Dave Woestenborghs
    101

    Hi Thomas,

    I think this is because you marked your action with the [HttpPost] attribute. This means it's only available for POST request. When you try to access it through your browser that is a GET request. Try to remove the [HttpPost] attribute or replace it with the [HttpGet] attribute.

    Dave

  • Thomas Won Nyheim 33 posts 145 karma points
    Jan 15, 2018 @ 09:47
    Thomas Won Nyheim
    0

    Thank you suman and Dave for your reply.

    Dave, you where right, I overlooked that part about post vs get, and got the response I needed from directly calling it.

Please Sign in or register to post replies

Write your reply to:

Draft