Use AJAX to submit form - Error 500

Topics: General, Troubleshooting
Mar 3, 2011 at 7:44 PM

Using Orchard 1.0.20  in IIS 7 and ASP.NET 4

I have a form that was added to the site as a Page. (in Plain text, no tags were removed)

The form is supposed to submit the data through AJAX to a form_pr.aspx file that will then send an email, usual processing stuff.

This form_pr.aspx file has been placed in the Themes/myTheme/ folder.

When I run the script, I get a 500 error.  The debugging shows this:


[ArgumentNullException: Value cannot be null.
Parameter name: serviceKey]
   Autofac.Util.Enforce.ArgumentNotNull(T value, String name) +95
   Autofac.Core.KeyedService..ctor(Object serviceKey, Type serviceType) +23
   Orchard.Mvc.OrchardControllerFactory.TryResolve(WorkContext workContext, Object serviceKey, T& instance) in d:\TeamCity\Projects\Orchard-1.x\src\Orchard\Mvc\OrchardControllerFactory.cs:17
   Orchard.Mvc.OrchardControllerFactory.GetControllerInstance(RequestContext requestContext, Type controllerType) in d:\TeamCity\Projects\Orchard-1.x\src\Orchard\Mvc\OrchardControllerFactory.cs:51
   System.Web.Mvc.DefaultControllerFactory.CreateController(RequestContext requestContext, String controllerName) +74
   System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext, IController& controller, IControllerFactory& factory) +196
   System.Web.Mvc.<>c__DisplayClass6.<BeginProcessRequest>b__2() +49
   System.Web.Mvc.<>c__DisplayClassb`1.<ProcessInApplicationTrust>b__a() +13
   System.Web.Mvc.SecurityUtil.<GetCallInAppTrustThunk>b__0(Action f) +7
   System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action) +22
   System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Func`1 func) +124
   System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state) +98
   System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContext httpContext, AsyncCallback callback, Object state) +50
   System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData) +16
   Orchard.Mvc.Routes.HttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData) in d:\TeamCity\Projects\Orchard-1.x\src\Orchard\Mvc\Routes\ShellRoute.cs:148
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +8841400
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +184

The JQuery AJax is pretty simple:

 type: "POST",  
url: "/Themes/myTheme/form_pc.aspx",

data: dataString,
success: function() {
return false;


Can you tell me what am I doing wrong and what is the best way to do this.

I have to add that the form, the Ajax and the processing script work just fine if I am not in the Orchard folder in the same server.  So my guess is that there is a web.config setting preventing the processing.


Mar 15, 2011 at 12:49 AM

This error message is horribly misleading (something that we fixed in more recent builds) but it almost invariably shows up when the system was unable to route the request. You should not put that file into the Themes folder: by design, the files in Themes are never served directly, except for the static files in styles, scripts, etc., and there is a special web.config allowing it in each of those folders. What you had before where the file was in a top-level directory that you owned, was just fine.