using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Umbraco.Web.Mvc;
public class ValidationSurfaceController : SurfaceController
{
public JsonResult EmailIsUnique(string email)
{
return this.Json(true);
}
}
This is my controller (will be used with a Remote data annotation).
My problem is that the url /umbraco/surface/ValidationSurface/EmailIsUnique/ (that seems to be the expected one) and /umbraco/surface/Validation/EmailIsUnique both returns a 404 error
Surface controllers are routed with a hidden field value rather than with a URL. I believe it has a name of "ufprt". I think you can use pretty much any URL so long as that hidden field is passed with the request.
What makes you think the correct URL would start with /umbraco/surface? On a related note, what version of Umbraco are you using?
It throws an exception when rendering the form field:
Error loading Partial View (file: ~/Views/MacroPartials/Global/Register.cshtml). Exception: System.InvalidOperationException: Impossibile trovare un url per la convalida remota. //Italian exception: means Impossible to find a url for remote convalidation
in System.Web.Mvc.RemoteAttribute.GetUrl(ControllerContext controllerContext)
Are you using Umbraco 7? If so, I wouldn't trust that documentation, which may be out of date. As I said, I believe surface controllers are now routed using a hidden field (that gets rendered when you call Html.BeginUmbracoForm). And surface controllers are auto-routed, so you don't need to map a route.
Routing Surface Controller
This is my controller (will be used with a Remote data annotation).
My problem is that the url /umbraco/surface/ValidationSurface/EmailIsUnique/ (that seems to be the expected one) and /umbraco/surface/Validation/EmailIsUnique both returns a 404 error
Some notes about surface controllers:
Usually looks like this:
That's not necessary if you are doing POST requests.
Thank you Nicholas.
I guessed the url following the documentation
I fixed the controller with the "AllowGet" behavior and now I can get it at /umbraco/surface/ValidationSurface/EmailIsUnique/
Unfortunately the Remote annotation still doesn't work
It throws an exception when rendering the form field:
I'm trying to get out of this...
this provide a strange behavior:
without the route /umbraco/surface/ValidationSurface/EmailIsUnique/ calls the "EmailIsUnique" action.
with the route the response is blank, but /umbraco/surface/ValidationSurface/EmailIsUnique/anythingIType calls the "EmailIsUnique" action.
I really don't get why this is happening.
Are you using Umbraco 7? If so, I wouldn't trust that documentation, which may be out of date. As I said, I believe surface controllers are now routed using a hidden field (that gets rendered when you call Html.BeginUmbracoForm). And surface controllers are auto-routed, so you don't need to map a route.
For anybody following this, I explain surface controller routing in a bit more detail in this message: https://our.umbraco.org/forum/umbraco-pro/contour/60788-Umbraco-Forms-and-Ajax#comment-233528
is working on a reply...