Copied to clipboard

Flag this post as spam?

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


  • EweltonChiba 6 posts 26 karma points
    Aug 21, 2023 @ 12:07
    EweltonChiba
    0

    My surface controller url return 404

    Im trying to make a post to a surface controller, but im getting error 404. Im trying to test using AJAX request and Postman

    My question: what am i missing?

    I tried every combination:

    1. /umbraco/surface/contratossurface/getcontratos
    2. /umbraco/surface/contratos/getcontratos

       public class ContratosSurfaceController : SurfaceController{
      
      
      [HttpPost]
      public async Task<ActionResult> GetContratos(ContentModel model, int draw, int start, int length, string filterValue)
      {
          //some codes
      
      
      
      return Json(new
      {
          draw = draw,
          recordsTotal = recordsTotal,
          recordsFiltered = recordsTotal,
          data = resultado
      }, JsonRequestBehavior.AllowGet);
      
      } }

    My request: https://localhost:44372/umbraco/surface/contratossurface/getcontratos

    {
    "filterValue": "hell world",
    "draw": 1, 
    "start": 0, 
    "length": 10
    }
    
  • Huw Reddick 1929 posts 6697 karma points MVP 2x c-trib
    Aug 21, 2023 @ 12:13
    Huw Reddick
    0

    doesn't look like you are posting the correct data in your ajax call

  • EweltonChiba 6 posts 26 karma points
    Aug 21, 2023 @ 12:18
    EweltonChiba
    0

    But during debug, the method is not even called.

  • Huw Reddick 1929 posts 6697 karma points MVP 2x c-trib
    Aug 21, 2023 @ 12:29
    Huw Reddick
    0

    It won't because your post signature does not match the method in your controller

    If you change your controller method to

    public async Task<ActionResult> GetContratos(Object obj)
    

    does your post then hit the controller method?

  • EweltonChiba 6 posts 26 karma points
    Aug 21, 2023 @ 13:01
    EweltonChiba
    0

    Nope, i change to this:

    [HttpPost]
        public ActionResult GetContratos(object obj)
        {
            //some code
            return Json(new
            {
                draw = 1,
                recordsTotal = 1,
    
            }, JsonRequestBehavior.AllowGet);
        }
    

    After disable the redirect to 404 page, i got this response:

    Server Error in '/' Application. Sequence contains no elements Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.InvalidOperationException: Sequence contains no elements

    Source Error:

    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

    Stack Trace:

    [InvalidOperationException: Sequence contains no elements] System.Linq.Enumerable.First(IEnumerable`1 source) +455 Umbraco.Core.Configuration.UmbracoSettings.ContentErrorsElement.get_Error404Collection() in D:\a\1\s\src\Umbraco.Core\Configuration\UmbracoSettings\ContentErrorsElement.cs:13 Umbraco.Web.Routing.ContentFinderByConfigured404.TryFindContent(PublishedRequest frequest) in D:\a\1\s\src\Umbraco.Web\Routing\ContentFinderByConfigured404.cs:57 Umbraco.Web.Routing.PublishedRouter.HandlePublishedContent(PublishedRequest request) in D:\a\1\s\src\Umbraco.Web\Routing\PublishedRouter.cs:459 Umbraco.Web.Routing.PublishedRouter.FindPublishedContentAndTemplate(PublishedRequest request) in D:\a\1\s\src\Umbraco.Web\Routing\PublishedRouter.cs:401 Umbraco.Web.Routing.PublishedRouter.PrepareRequest(PublishedRequest request) in D:\a\1\s\src\Umbraco.Web\Routing\PublishedRouter.cs:135 Umbraco.Web.UmbracoInjectedModule.ProcessRequest(HttpContextBase httpContext) in D:\a\1\s\src\Umbraco.Web\UmbracoInjectedModule.cs:138 System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +223 System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step) +232 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +100

  • Huw Reddick 1929 posts 6697 karma points MVP 2x c-trib
    Aug 21, 2023 @ 13:30
    Huw Reddick
    0

    does it reach the method before erroring? if not then you have something configured incorrectly somewhere as it still appears to be trying to use your 404 settings

  • EweltonChiba 6 posts 26 karma points
    Aug 21, 2023 @ 14:49
    EweltonChiba
    0

    I did a clean install, same problem.

    https://postimg.cc/w305QT7v

  • Huw Reddick 1929 posts 6697 karma points MVP 2x c-trib
    Aug 21, 2023 @ 14:57
    Huw Reddick
    0

    what does your view and js look like where you are doing the post

  • EweltonChiba 6 posts 26 karma points
    Aug 21, 2023 @ 14:59
    EweltonChiba
    0

    Im testing using postman

    { "draw": 1, "start": 0, "length": 10, "filterValue": "test" }

  • Huw Reddick 1929 posts 6697 karma points MVP 2x c-trib
    Aug 21, 2023 @ 15:02
    Huw Reddick
    0

    I don't think postman will work posting to a surface controller, although never tried myself. I will give it a try.

  • Huw Reddick 1929 posts 6697 karma points MVP 2x c-trib
    Aug 21, 2023 @ 12:31
    Huw Reddick
    0

    FYI

    This one is correct /umbraco/surface/contratossurface/getcontratos

  • EweltonChiba 6 posts 26 karma points
    Aug 21, 2023 @ 15:30
    EweltonChiba
    0

    I found the problem. My project was created from Empty MVC project. So, i dont have Global.asax.cs. When i created a new project from MVC project, o routing worked.

    Now, i will try configure manually the missing files.

Please Sign in or register to post replies

Write your reply to:

Draft