title: Routing a custom controller in Orchard CMS
body: <p>I'm having some trouble setting up the routing to a custom controller in Orchard.</p>
  
  <p>I've created a View:</p>
  
  <pre><code>@model dynamic
  @{
      Script.Require("jQuery");
  }
  @using (Html.BeginForm("Send", "Email", FormMethod.Post, new { id = "contactUsForm" }))
  {
      &lt;fieldset&gt;
          &lt;legend&gt;Contact Us&lt;/legend&gt;
          &lt;div class="editor-label"&gt;Name:&lt;/div&gt;
          &lt;div class="editor-field"&gt;
              @Html.TextBox("Name", "", new {style = "width: 200px"})
          &lt;/div&gt;
          &lt;div class="editor-label"&gt;Email Address:&lt;/div&gt;
          &lt;div class="editor-field"&gt;
              @Html.TextBox("Email", "", new {style = "width: 200px"})
          &lt;/div&gt;
          &lt;div class="editor-label"&gt;Telephone Number:&lt;/div&gt;
          &lt;div class="editor-field"&gt;
              @Html.TextBox("Telephone", "", new {style = "width: 200px"})
          &lt;/div&gt;
          &lt;div class="editor-label"&gt;Message:&lt;/div&gt;
          &lt;div class="editor-field"&gt;
              @Html.TextArea("Message", "", new {style = "width: 200px"})
          &lt;/div&gt;
          &lt;br/&gt;
          &lt;input id="ContactUsSend" type="button" value="Submit" /&gt;
      &lt;/fieldset&gt;
  }
  @using (Script.Foot()) {
      &lt;script&gt;
          $(function() {
              $('#ContactUsSend').click(function () {
                  alert('@Url.Action("Send", "Email")');
                  var formData = $("#contactUsForm").serializeArray();
  
                  $.ajax({
                      type: "POST",
                      url: '@Url.Action("Send", "Email")',
                      data: formData,
                      dataType: "json",
                      success: function (data) {
                          alert(data);
                      }
                  });
              });
          });
      &lt;/script&gt;
  }
  </code></pre>
  
  <p>With a Controller:</p>
  
  <pre><code>public class EmailController : Controller
      {
          [HttpPost]
          public ActionResult Send()
          {
              var orchardServices = DependencyResolver.Current.GetService&lt;IOrchardServices&gt;();
              var messageHandler = DependencyResolver.Current.GetService&lt;IMessageManager&gt;();
              var svc = new ContactUsService(orchardServices, messageHandler);
              svc.DoSomething();
              return new EmptyResult();
          } 
      }
  </code></pre>
  
  <p>And setup the route:</p>
  
  <pre><code>public class Routes : IRouteProvider {
          public void GetRoutes(ICollection&lt;RouteDescriptor&gt; routes) {
              foreach (var routeDescriptor in GetRoutes()) {
                  routes.Add(routeDescriptor);
              }
          }
  
          public IEnumerable&lt;RouteDescriptor&gt; GetRoutes() {
              return new[] {
                  new RouteDescriptor {
                      Priority = 15,
                      Route = new Route(
                          "ContactUsWidget",
                          new RouteValueDictionary {
                              {"area", "ContactUsWidget"},
                              {"controller", "Email"},
                              {"action", "Send"}
                          },
                          new RouteValueDictionary(),
                          new RouteValueDictionary {
                              {"area", "ContactUsWidget"}
                          },
                          new MvcRouteHandler())
                  }
              };
          }
      }
  </code></pre>
  
  <p>But when I click the submit button, it tries to post to </p>
  
  <blockquote>
    <p>OrchardLocal/Contents/Email/Send</p>
  </blockquote>
  
  <p>and obviously fails.  Can anyone point me in the direction of what I'm doing wrong? </p>