1

I have a custom tab on the right-hand side(where we can see item fields) for my items in content editor and I am loading a MyTab.cshtml page within this custom tab. This .cshtml I'm trying to post a request to Sitecore but I keep getting a 404 as if the route doesn't exist.

Let's say I have a MyController with a MyAction within it to post, what would be the correct route to be able to post for this action within the shell site? I have a working route for my test site(which is the frontend site) but not finding a way to do that within Sitecore.

1 Answer 1

2

In a Sitecore site you need to register your custom routes in a specific way so that Sitecore does not loose them when it initialises it's own routes. Specifically you need to register your custom route in the initialize pipeline. I'm guessing that perhaps your not doing this and that is why your route is not working.

If you had a controller like so:

public class MyController : Controller
{
    [HttpGet]
    public ActionResult MyAction()
    {

    }

    [HttpPost]
    public ActionResult MyAction(string field1, string field2)
    {

    }
 }

You would also need something like the following to register the route:

  public class RegisterCustomRoute
  {
    public virtual void Process(PipelineArgs args)
    {
      Register();
    }

    public static void Register()
    {
      RouteTable.Routes.MapRoute("CustomRoute", "custom/myroute/{controller}/{action}/{id}");
    }

  }

And a config patch like so:

<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
     <sitecore>
          <pipelines>
               <initialize>
                    <processor type="MyNamespace.RegisterCustomRoute, MyAssembly" patch:before="processor[@type='Sitecore.Mvc.Pipelines.Loader.InitializeRoutes, Sitecore.Mvc']" />
               </initialize>
          </pipelines>
     </sitecore>
</configuration>

There is more info on this here:

https://kb.sitecore.net/articles/700677

Requested document not found when using MVC routes

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.