Get error when I called RedirectToAction in server

Environment.

Develop : VisualStudio2012 MVC4 .NetFrameWrok4.5
Server : WindowsServer2008 R2 iis 7.5

If i failed log in. I call -> return RedirectToAction("LoginError", "Search"); It is working successfully when i debug on VisualStudio. But, It is return error page on server.

This is error message.

Server Error in '/' Application Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Stack Trace:

[InvalidOperationException:
System.Web.Mvc.RedirectToRouteResult.ExecuteResult(ControllerContext context) +479
System.Web.Mvc.<>c__DisplayClass1a.b__17() +33 System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func 1 continuation) +613
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList
1 continuation) +613
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList
1 continuation) +613
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList
1 filters, ActionResult actionResult) +263
System.Web.Mvc.Async.<>c__DisplayClass25.b__22(IAsyncResult asyncResult) +230
System.Web.Mvc.<>c__DisplayClass1d.b__18(IAsyncResult asyncResult) +28
System.Web.Mvc.Async.<>c__DisplayClass4.b__3(IAsyncResult ar) +20 System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +53
System.Web.Mvc.Async.<>c__DisplayClass4.b__3(IAsyncResult ar) +20
System.Web.Mvc.<>c__DisplayClass8.b__3(IAsyncResult asyncResult) +42
System.Web.Mvc.Async.<>c__DisplayClass4.b__3(IAsyncResult ar) +20
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +453 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +371

I found this. RedirectToAction Causes "No route in the route table matches the supplied values" in ASP.NET MVC 3

return RedirectToAction("ActionName", "ControllerName", new { area = "AreaName" });

But I can't understand mean of new { area = "AreaName" } . I didn't know what is this.

please teach me about this if you know. Thank you.


Unless you have defined Areas you will have no need for that. To get an idea what the areas are check this MSDN article.

In short they are like a separate part of your MVC application.

Regarding your error I would assume that using this overload return RedirectToAction("ActionName", "ControllerName") should be enough but without seeing the code it is just an assumption.

Also check the full list of overload for redirect to action in this article.


I found solution. Reason of the problem is Routeconfig.cs. I wrote only this.

        routes.MapRoute(
            name: "SearchPart_three_para",
            url: "{controller}/{action}/{id}/{requestcode}/{systemid}",
            defaults: new
            {
                controller = "Search",
                action = "SearchPart",
                id = UrlParameter.Optional,
                requestcode = UrlParameter.Optional,
                systemid = UrlParameter.Optional
            }
        );

And i edited like this.

        routes.MapRoute(
            name: "SearchPart",
            url: "{controller}/{action}",
            defaults: new
            {
                controller = "Search",
                action = "SearchPart"
            }
        );

        routes.MapRoute(
            name: "SearchPart_three_para",
            url: "{controller}/{action}/{id}/{requestcode}/{systemid}",
            defaults: new
            {
                controller = "Search",
                action = "SearchPart",
                id = UrlParameter.Optional,
                requestcode = UrlParameter.Optional,
                systemid = UrlParameter.Optional
            }
        );

reference here. ASP.NET MVC : Empty ActionLinks appearing

Thank you!

链接地址: http://www.djcxy.com/p/72702.html

上一篇: 在ASP.NET MVC中从数据库加载Razor视图5

下一篇: 当我在服务器中调用RedirectToAction时发生错误