So inside my ASP.NET MVC View I have a conditional statement to redirect users to a different page.
What is the best way to do this?
What is the Controller.RedirectToAction() equivalent for a View?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This sounds like a perversion of MVC and if you can’t do the redirect in the controller, then your logic is not correct.
However, here is what I would use if I didn’t have access to the controller for whatever reason:
Update
In your comment, you mentioned it’s because you’re doing role checking and you don’t want to do this in every controller/action. If that’s the case, then here is something that you might like to consider:
Create a base controller class and have every controller extend from this class.
In your base controller, have an OnActionExecuting method. In here, you have something like this: