[ASP. NET MVC] Child actions is not allowed to perform redirect

Source: Internet
Author: User

I encountered this problem when I was developing with MVC (Surfacecontroller) under the Umbraco platform.

Memberedit is a partial View

[Httpget][actionname ("Memberedit")]  PublicActionResult Membereditget () {if(Members.getcurrentloginstatus (). isLoggedIn) {varCurrentprofilemodel =NewGallagher.Fuelsystems.Core.Models.ProfileModel () {//Some codes here                }; returnPartialview ("Memberedit", Currentprofilemodel); }            Else            {                returnPartialview ("Memberlogin"); //return Redirect ("/login");            }        } 

At first, in the Else statement, I was using return Redirect ("/login"); I reported this error, and then I changed it to return Partialview ("Memberlogin"); There's no problem.

On the Internet to search for this error message, the explanation is probably as follows:

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

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

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

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 and then there WA s really no purpose to going through the view of the first place, as the outer action could has delegated the work Approp Riately on its own.

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

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

[ASP. NET MVC] Child actions is not allowed to perform redirect

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.