tags:

views:

224

answers:

2

In Controller, RedirectToAction("Error") can redirect to error page. How to write code in view code to allow the page redirected to error.aspx view?

+2  A: 

Don't. The decision on which view to display is to be made by the controller, and should not be redone by the view.

Jørn Schou-Rode
The reason is: normally, the error is processed by controller. With MVC, when you navigate the view by action, this is okay. But when users know your url, maybe they visit the view in random way. For example, you have home, create, edit, ..... It's supposed to visit home firstly to initialize something, then create, edit,..... But If I know url, maybe I visit edit firstly, some exception may not be captured by any action in controller(occurred in master page, for example), so I want to have ability in view to redirect user to a error page, say, your reqest can not be processed, etc.
KentZhou
A: 

@Jørn is right, but what kinds of errors are you predicting to show up in your view?

If you gave some details on why you're thinking about this, we might be able to suggest some better alternatives instead of simply saying "don't do this."

Dennis Palmer