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();
}
}
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.
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.
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.<>c__DisplayClass1a.<InvokeActionResultWithFilters>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.<>c__DisplayClass1a.<>c__DisplayClass1c.<InvokeActionResultWithFilters>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.<>c__DisplayClass1d.<BeginExecuteCore>b__18(IAsyncResult asyncResult)
at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass4.<MakeVoidDelegate>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.<>c__DisplayClass8.<BeginProcessRequest>b__3(IAsyncResult asyncResult)
at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass4.<MakeVoidDelegate>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)`
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!
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 ...
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.
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:
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:
Here is the relevant portion of my view:
I don't think they're related to the issue, but I could post my repository and model if that will help.
I was able to get the form to submit by switching the
@using
statement in my view to:I would still like to know how to get Umbraco to recognize my /App_Code/ custom surface controllers when using
BeginUmbracoForm
.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.
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
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, IDictionary
2 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.<>c__DisplayClass1a.<InvokeActionResultWithFilters>b__17() at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func
1 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.<>c__DisplayClass1a.<>c__DisplayClass1c.<InvokeActionResultWithFilters>b__19() at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList
1 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.<>c__DisplayClass1d.<BeginExecuteCore>b__18(IAsyncResult asyncResult) at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult
1.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.<>c__DisplayClass8.<BeginProcessRequest>b__3(IAsyncResult asyncResult) at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult
1.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)`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!
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 useBeginForm()
. Once this route was commented out,BeginUmbracoForm()
started to work again.Is this a bug with
BeginUmbracoForm()
? Or is it by design ...Matthew: Are you placing your SurfaceController in the App_Code directory? Remember to make it belong to a namespace e.g.:
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
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.
is working on a reply...