Amresh Kumar Singh
Amresh Kumar Singh

Reputation: 133

MVC RedirectToAction Not working Properly

return RedirectToAction("Index", "Dashboard");

URL Should be

http://localhost:6574/Dashboard/Index

But this is showing

http://localhost:6574/Dashboard/

Showing Error enter image description here

public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
            routes.IgnoreRoute("{*x}", new { x = @".*\.asmx(/.*)?" });
            routes.IgnoreRoute("{resource}.ashx/{*pathInfo}");
            routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "UserLogin", action = "Index", id = UrlParameter.Optional }
            );
        }

Upvotes: 0

Views: 116

Answers (2)

Smit Patel
Smit Patel

Reputation: 3267

May be this one can helps you, Set this in your applicaiton's web.config

<system.webServer>
  <modules runAllManagedModulesForAllRequests="true"></modules>
   <handlers>
    <remove name="UrlRoutingHandler"/>
   </handlers>
</system.webServer>

Also you can do this,

<system.webServer>
  <modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>

Upvotes: 1

Alex
Alex

Reputation: 38539

This is likely because your route config contains something like

routes.MapRoute(
    name: "Default",
    url: "{controller}/{action}/{id}",
    defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);

Where by your default action is Index
Meaning, when you do RedirectToAction("Index", "Dashboard"); it ignores the index, because this is already the default.

Upvotes: 2

Related Questions