zoukankan      html  css  js  c++  java
  • [ASP.NET MVC] Child actions are not allowed to perform redirect

    我在Umbraco平台下,用MVC(SurfaceController)开发时,遇到这个问题

    MemberEdit是一个partial View

    [HttpGet]
    [ActionName("MemberEdit")]
     public ActionResult MemberEditGet()
      {
            if (Members.GetCurrentLoginStatus().IsLoggedIn)
             {
                   
                    var currentProfileModel = new Gallagher.Fuelsystems.Core.Models.ProfileModel()
                    {
    
                       // some codes here
                    };
    
                    return PartialView("MemberEdit", currentProfileModel);
    
                }
    
                else
                {
                    return PartialView("MemberLogin");
    
    
                    //return Redirect("/Login");
                }
    
            } 

    刚开始,在else语句中,我使用的是 return Redirect("/Login"); 就报这个错误,后来我改为 return PartialView("MemberLogin"); 就没问题了

    在网上搜索了关于这个错误信息,解释大概如下:

    -------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    The limitation exists because MVC has already started rendering a view to the client. The effect of redirecting from this point is undefined. It could work perfectly, it could continue rendering the original view without redirecting, it could throw a different exception, etc.

    Since the result of performing this action is undefined, the framework blocks it. In practice, RenderAction should never be used to render anything other than a view (or view-like content) for similar reasons.

    In your particular case, the outer action should redirect. If you're just going to end up redirecting from within the view anyway without showing anything to the user, then there was really no purpose to going through the view in the first place, as the outer action could have delegated the work appropriately on its own.

    The redirect info is stored in response header. However, the response is already being sent when child action is run so headers can't be written.

    -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

  • 相关阅读:
    (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated UXXXXXXXX escape 错误
    Pandas_key_point
    鲁棒性、稳定性、非脆弱性
    防止过拟合的处理方法
    Python中的random模块
    Python reload(sys)找不到,name 'reload' is not defined
    sigmoid 和 soft-max总结
    2.7 Structured Regression Models
    2.x ESL第二章习题2.4
    2.6. Statistical Models, Supervised Learning and Function Approximation
  • 原文地址:https://www.cnblogs.com/wphl-27/p/5801461.html
Copyright © 2011-2022 走看看