0

Can you help me with The resource cannot be found error, for ActionResult Create and View Create

Every other controller/view are working and I cant find out whats wrong with this one.

Here is my RouteConfig:

public static class RouteConfig
{
    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
        routes.LowercaseUrls = true;
        routes.MapRoute("Default", "{controller}/{action}/{id}", new
        {
            controller = AutoParts.Domain.Settings.IntegrationType == "Try" ? "Search" : "Home",
            action = "Index",
            id = UrlParameter.Optional
        }).RouteHandler = new DashRouteHandler();
    }
}

This is DashRouteHandler:

public class DashRouteHandler : MvcRouteHandler
    {            
        protected override IHttpHandler GetHttpHandler(RequestContext requestContext)
        {
            var routeValues = requestContext.RouteData.Values;

            routeValues["action"] = routeValues["action"].UnDash();
            routeValues["controller"] = routeValues["controller"].UnDash();

            return base.GetHttpHandler(requestContext);
        }
    }

Here is My Controller:

[HttpPost]
        public ActionResult Create(Mapper20170129 mapper)
        {
            if (ModelState.IsValid)
            {


                    repository.AddArticle(mapper);

                    return RedirectToAction("Index");
                }
                else
                {
                ModelState.AddModelError("", "Error.");

                }

            return View(mapper);
        }

I've got other Controllers with Create ActionResult and Create View but I don't have any problems and getting this not found error

Thank You in advance for help

user3782230
  • 145
  • 1
  • 3
  • 11
  • Might sound a really simple suggestion, but double-check you are sending a HTTP `POST` request to your endpoint from the client code? Have you tried using something like Fiddler (to intercept) or Postman (to create) to see/contrive a request and see what happens? – Geoff James Nov 17 '17 at 20:31
  • 1
    which line is throwing the exception? whats the exception detail? – Steve Nov 17 '17 at 20:52
  • FYI - customizing the route handler to change the business logic of routes is a flawed approach. The main issue with this is that your outgoing routes (the URLs that are generated by `ActionLink`) won't match your incoming routes. On the other hand, if you subclass the `Route` or [`RouteBase`](https://stackoverflow.com/a/31958586/) class, you can can change both incoming and outgoing routes so they match. – NightOwl888 Nov 17 '17 at 21:27

0 Answers0