The PRG pattern in asp.net mvc

Source: Internet
Author: User
Tags html page response code

When you surf the Internet, have you ever seen the following thing?

As a web developer, we know what it means--the form has been posted to the page, but is trying to refresh the same page. I don't know if it's significant to study the subject, but I can imagine that my grandmother certainly didn't know what to do when she met the picture. Use PRG mode.

What is the PRG mode?

Although the PRG model is not something new, it's in. NET community has not emphasized much. PRG says "Post/redirect/get" and the rest is for Wikipedia to explain:

Instead of returning directly to an HTML page, the post operation returns a redirection command (using the HTTP 303 response code (sometimes 302) and the HTTP "Location" response header) to boot the browser to load another page with an HTTP GET request. This result page can be safely saved or reloaded as a bookmark without unintended side effects.

Although WebForms can do this, it is very complex, because the postback model of the page needs to be back-made to implement the click of the button. The MVC framework makes it very easy to implement the PRG pattern.

How do you do it? Give me an example?

I'll use a login function as an example. If the login succeeds, the user will be redirected to his account page, otherwise it will be redirected back to the login page.

Related Article

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.