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:
/umbraco/surface/contratossurface/getcontratos
/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
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
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
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.
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:
/umbraco/surface/contratos/getcontratos
My request: https://localhost:44372/umbraco/surface/contratossurface/getcontratos
doesn't look like you are posting the correct data in your ajax call
But during debug, the method is not even called.
It won't because your post signature does not match the method in your controller
If you change your controller method to
does your post then hit the controller method?
Nope, i change to this:
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
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
I did a clean install, same problem.
https://postimg.cc/w305QT7v
what does your view and js look like where you are doing the post
Im testing using postman
{ "draw": 1, "start": 0, "length": 10, "filterValue": "test" }
I don't think postman will work posting to a surface controller, although never tried myself. I will give it a try.
FYI
This one is correct
/umbraco/surface/contratossurface/getcontratos
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.
is working on a reply...