Copied to clipboard

Flag this post as spam?

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


  • Matthew Kirschner 323 posts 611 karma points
    Feb 23, 2015 @ 17:39
    Matthew Kirschner
    0

    BeginUmbracoForm can't find my custom surface controller on submisison

    I'm trying to create a custom form in a VS Website Project using Umbraco 7.2.1 and several forms guides (including this one from Our).

    Everything works well up until I attempt to submit my test data, in which I get the exception:

    System.InvalidOperationException: Could not find a Surface controller route in the RouteTable for controller name PatentsSurface
    

    Am I missing a step to get Umbraco to recognize my surface controller?

    Since this is a website project, I have all my code inside subfolders within the AppCode folder. So the controller in question has a filepath of /AppCode/Controllers/PatentsSurfaceController.cs

    Here is my SurfaceController code:

    public class PatentsSurfaceController : Umbraco.Web.Mvc.SurfaceController
    {
        [HttpPost]
        public ActionResult AddPatent(PatentsModel model)
        {
            if (!ModelState.IsValid)
            {
                return CurrentUmbracoPage();
            }
    
            model.DateModified = DateTime.Now;
    
            var repo = new PatentsRepository();
            repo.Insert(model);
    
            return RedirectToCurrentUmbracoPage();
        }
    }
    

    Here is the relevant portion of my view:

    @using (Html.BeginUmbracoForm<PatentsSurfaceController>("AddPatent"))
        {
            <div class="row">
                <div class="small-12 medium-8 medium-centered columns">
                    @Html.LabelFor(x => x.PatentName)
                    @Html.TextBoxFor(x => x.PatentName)                
                    <input type="submit" value="Add Patent" class="button success" />
                </div>
            </div>
        }
    

    I don't think they're related to the issue, but I could post my repository and model if that will help.

  • Matthew Kirschner 323 posts 611 karma points
    Feb 23, 2015 @ 20:26
    Matthew Kirschner
    0

    I was able to get the form to submit by switching the @using statement in my view to:

    @using (Html.BeginForm("AddPatent", "PatentsSurface")
    

    I would still like to know how to get Umbraco to recognize my /App_Code/ custom surface controllers when using BeginUmbracoForm.

  • Matthew Kirschner 323 posts 611 karma points
    Feb 24, 2015 @ 19:22
    Matthew Kirschner
    0

    Upgrading to 7.2.2 and going back to using BeginUmbracoForm, I still can't get this to work in my project. I've found some old posts from people with a similar issue and their solution was to give their controllers a namespace. I've done this and Umbraco still fails to find my surface controller.

  • Rafael Dominguez 2 posts 22 karma points
    Feb 18, 2016 @ 15:53
    Rafael Dominguez
    0

    We have pretty much the same problem you are describing.

    • SurfaceController in App_code\SurfaceControllers\PartnerRegistrationSurfaceController.cs

    • Partial View: using (Html.BeginUmbracoForm<PartnerRegisterSurfaceController>("PartnerForm", null, new { @id="frmRegistration" }))

    The only difference is that for us this code works until a clear cache (or alike) occurs. After this we get the 'Unable to find surface controller' error.

    If I then move the surface controller file (say one level up) the compile will find it, cache it and it's all good once more. Any help/suggestion is Appreciated.

    -Umbraco version 7.2.8 assembly: 1.0.5675.23466

    `2016-02-18 04:40:23,491 [60] ERROR Umbraco.Core.UmbracoApplicationBase - [P8900/T5/D22] An unhandled exception occurred
    

    System.InvalidOperationException: Could not find the surface controller of type SurfaceControllers.PartnerRegisterSurfaceController at Umbraco.Web.HtmlHelperRenderExtensions.BeginUmbracoForm(HtmlHelper html, String action, Type surfaceType, Object additionalRouteVals, IDictionary2 htmlAttributes, FormMethod method) at Umbraco.Web.HtmlHelperRenderExtensions.BeginUmbracoForm[T](HtmlHelper html, String action, Object additionalRouteVals, Object htmlAttributes) at ASP._Page_Views_Partials_partnerregistrationform_cshtml.Execute() in c:\inetpub\wwwroot\SOTIWEB2015\Views\Partials\PartnerRegistrationForm.cshtml:line 34 at System.Web.WebPages.WebPageBase.ExecutePageHierarchy() at System.Web.Mvc.WebViewPage.ExecutePageHierarchy() at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) at System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance) at System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer) at Umbraco.Core.Profiling.ProfilingView.Render(ViewContext viewContext, TextWriter writer) at System.Web.Mvc.HtmlHelper.RenderPartialInternal(String partialViewName, ViewDataDictionary viewData, Object model, TextWriter writer, ViewEngineCollection viewEngineCollection) at System.Web.Mvc.Html.PartialExtensions.Partial(HtmlHelper htmlHelper, String partialViewName, Object model, ViewDataDictionary viewData) at System.Web.Mvc.Html.PartialExtensions.Partial(HtmlHelper htmlHelper, String partialViewName, Object model) at ASP._Page_Views_tmpl_PartnerForm_cshtml.Execute() in c:\inetpub\wwwroot\SOTIWEB2015\Views\tmpl_PartnerForm.cshtml:line 58 at System.Web.WebPages.WebPageBase.ExecutePageHierarchy() at System.Web.Mvc.WebViewPage.ExecutePageHierarchy() at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) at System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance) at System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer) at Umbraco.Core.Profiling.ProfilingView.Render(ViewContext viewContext, TextWriter writer) at System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) at System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult) at System.Web.Mvc.ControllerActionInvoker.&lt;&gt;c__DisplayClass1a.&lt;InvokeActionResultWithFilters&gt;b__17() at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func1 continuation) at System.Web.Mvc.ControllerActionInvoker.<>cDisplayClass1a.<>cDisplayClass1c.<InvokeActionResultWithFilters>b19() at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func1 continuation) at System.Web.Mvc.ControllerActionInvoker.&lt;&gt;c__DisplayClass1a.&lt;&gt;c__DisplayClass1c.&lt;InvokeActionResultWithFilters&gt;b__19() at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList1 filters, ActionResult actionResult) at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>cDisplayClass25.<>cDisplayClass2a.<BeginInvokeAction>b20() at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>cDisplayClass25.<BeginInvokeAction>b22(IAsyncResult asyncResult) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult1.End() at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) at System.Web.Mvc.Controller.&lt;&gt;c__DisplayClass1d.&lt;BeginExecuteCore&gt;b__18(IAsyncResult asyncResult) at System.Web.Mvc.Async.AsyncResultWrapper.&lt;&gt;c__DisplayClass4.&lt;MakeVoidDelegate&gt;b__3(IAsyncResult ar) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult1.End() at System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) at System.Web.Mvc.Async.AsyncResultWrapper.<>cDisplayClass4.<MakeVoidDelegate>b3(IAsyncResult ar) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult1.End() at System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) at System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) at System.Web.Mvc.MvcHandler.&lt;&gt;c__DisplayClass8.&lt;BeginProcessRequest&gt;b__3(IAsyncResult asyncResult) at System.Web.Mvc.Async.AsyncResultWrapper.&lt;&gt;c__DisplayClass4.&lt;MakeVoidDelegate&gt;b__3(IAsyncResult ar) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult1.End() at System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) at System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)`

  • James Saliba 14 posts 87 karma points
    Jan 16, 2017 @ 23:23
    James Saliba
    0

    Has anyone figured out a reason for this behaviour? I'm running into the same "Could not find a Surface controller" problem randomly on cache clears (e.g. touching the web.config, or sometimes just editing other files in App_Code folder).

    I'm on v7.5.2 and it's still happening. My custom controllers are just in .cs files in the base of the App_Code folder, sticking them in the Umbraco.Web.Controllers namespace and fully qualifying class names I inherit from... still, randomly run into this problem. And that doesn't inspire confidence!

  • Kieron McIntyre 117 posts 360 karma points
    Jun 09, 2017 @ 11:20
    Kieron McIntyre
    0

    Late to the party as always ... but I came across this issue today. I had used a single routes.MapUmbracoRoute() in my routing to target an action on surface controller X and this seemed to be the cause of my issue.

    Using BeginUmbracoForm() wouldn't work for any actions on controller X, even though the actual routes seemed to still be registered - as you have pointed out, you can still use BeginForm(). Once this route was commented out, BeginUmbracoForm() started to work again.

    Is this a bug with BeginUmbracoForm()? Or is it by design ...

  • Simon Justesen 74 posts 193 karma points
    Jun 09, 2017 @ 12:24
    Simon Justesen
    0

    Matthew: Are you placing your SurfaceController in the App_Code directory? Remember to make it belong to a namespace e.g.:

    namespace YourNamespace.App_Code {
    
    public class ShopSurfaceController : SurfaceController {
    ... etc...
    }
    
    }
    

    I've had similar problems until I tried that. It doesn't seem like its documented anywhere.

    Edit: Ouch, realized it's an old post.. The above-mentioned fix is still valid, though

  • Matthew Kirschner 323 posts 611 karma points
    Jun 09, 2017 @ 12:54
    Matthew Kirschner
    0

    I don't quite recall what my solution was here but I think it had something to do with switching to a Visual Studio Project instead of a VS Website. Looking at my working code now, it's exactly the same as what I had in my original post and the only things that have changed are project setup and Umbraco versions.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies