5

What is proper way to stop cshtml view rendering after redirect? Can I do return inside cshtml?

@{
 if (someCondition) {       
        Response.Redirect("/login");
        return;
    }
 }
}
<!DOCTYPE html>
....
8
  • 8
    the proper way is to specify your logic in the Controller, not in the view Commented Jun 24, 2015 at 17:39
  • That is solution for ideal world. But In my case I have access only to view. Commented Jun 24, 2015 at 17:41
  • get access to the controller then, or specify a javascript redirect if you absolutely must. Commented Jun 24, 2015 at 17:42
  • In my case I need to stop rendering because it does not have all data to render. So JS redirect is not solution. Commented Jun 24, 2015 at 17:45
  • 2
    why do you not have access to the controller? Commented Jun 24, 2015 at 17:45

1 Answer 1

9

I believe this may be a duplicate question, to which the short answer is:

It's perfectly valid to return; from within cshtml; however there is usually a better way.

Sources:

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.