使用return RedirectToAction()时从另一个页面重定向时页面不加载RedireToAction()

问题描述:

嗨我正面临一种奇怪的情况,当我试图从另一页面重定向到一个页面时,它不会加载。当我通过添加断点进行检查时,指针将进入控制器,也进入视图但不加载。任何人都可以解释原因和可能的解决方案使用return RedirectToAction()时从另一个页面重定向时页面不加载RedireToAction()

检查错误日志后,我得到了以下信息

2016-09-27 09:18:27,927 [7] ERROR PPMS.Web.Controllers.BaseController [(null)] - { Controller = TrackingDevice, Action = Add, Exception = System.Web.HttpException (0x80004005): Cannot redirect after HTTP headers have been sent. 
    at System.Web.HttpResponse.Redirect(String url, Boolean endResponse, Boolean permanent) 
    at System.Web.HttpResponseWrapper.Redirect(String url) 
    at PPMS.Web.CustomAttributes.SessionExpireAttribute.OnActionExecuting(ActionExecutingContext filterContext) in d:\PPMS\PPMS.Web\CustomAttributes\SessionExpireAttribute.cs:line 20 
    at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.InvokeActionMethodFilterAsynchronouslyRecursive(Int32 filterIndex) 
    at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.InvokeActionMethodFilterAsynchronouslyRecursive(Int32 filterIndex) 
    at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass33.<BeginInvokeActionMethodWithFilters>b__31(AsyncCallback asyncCallback, Object asyncState) 
    at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.CallBeginDelegate(AsyncCallback callback, Object callbackState) 
    at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.Begin(AsyncCallback callback, Object state, Int32 timeout) 
    at System.Web.Mvc.Async.AsyncResultWrapper.Begin[TResult](AsyncCallback callback, Object state, BeginInvokeDelegate beginDelegate, EndInvokeDelegate`1 endDelegate, Object tag, Int32 timeout) 
    at System.Web.Mvc.Async.AsyncControllerActionInvoker.BeginInvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters, AsyncCallback callback, Object state) 
    at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass21.<BeginInvokeAction>b__19(AsyncCallback asyncCallback, Object asyncState) } 
+1

“不加载”是一个非常广泛的声明。您需要提供更多信息。请花点时间阅读[如何创建最小,完整和可验证的示例](http://*.com/help/mcve) – Shyju

+0

您能否显示您的代码,如果有的话还可以添加异常。 –

+0

没有例外是问题是在我的列表页面。第一个列表页面会出现,但是当我尝试添加新项目时,提交它应该重定向到相同的列表页面,当时它不是正在提交 –

这可能是因为使用创造了呼叫重定向响应之前的操作过滤器中的一个被调用。你可以使用

if (!Response.IsRequestBeingRedirected) 
// Will not be called 
Response.Redirect(...); 

来帮助这里。 (见this link)。