Do not put such code in views. Views should only be for your display layout as much as possible. You can put this try catch in your controller action method, which passes data to the view.
public ActionResult GetUser(int id) { try {
Keep in mind that one of the things that MVC emphasizes is the separation of concerns. Presentations should be clean and readable. Markup.
Shyju source share