且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

邮政重定向获取ASP.NET MVC和验证REST风格的URL

更新时间:2022-12-09 12:16:15

您应该只做重定向如果表单信息有效;在提交错误的情况下,返回从相同的编辑方法的看法。

You should only do the redirect if the form information is valid; in the case of submission errors, return the view from the same Edit method.

这样做,这样的与PRG兼容的,因为如果你的模型是无效的,你是不是允许任何更改到服务器上对象的状态进行。 PRG的主要目的是prevent多个帖子,可以改变在联合国predictable方法服务器对象(例如,业务对象,数据库表等)的状态;在验证的例子,但是,用户可以打,因为他们想重新提交多次,他们将永远被送回验证错误的初步意见 - 没有任何服务器上的变化。因此,你必须是正确的:如果你的模型在presentation层通过验证只能发出重定向

Doing it this way is compliant with PRG, because if your model is invalid, you are not allowing any changes to be made to the state of objects on the server. PRG is designed primarily to prevent multiple posts that can change the state of server objects (e.g., business objects, database tables, etc.) in unpredictable ways; in your validation example, however, the user can hit resubmit as many times as they want and they will always be sent back to the initial view with validation errors--nothing on the server changes. Therefore, you have it right: only issue the Redirect if your model passes validation in your presentation tier.