开发者

MVC - 404 from Model

Using the MVC pattern, is the following acceptable?

  • User browses to www.example.com/blog/post/4
  • 4 validates as a potential id, so the controller asks the model to return post 4
  • The model queries the database, but finds that no post with an id of 4 exists
  • The model 开发者_如何学运维redirects the user to the site's 404 error page

Note that the desired action is a 404, not a message of "Post #4 doesn't exist."

Now, I could have the model send an error back to the controller, and have the controller redirect to the 404 page, but is this necessary? Is it proper to do so directly from the model?

Thanks!


I would return null from the model, then check for null in the controller and throw new HttpException(404, "Post not found").

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜