title: Display error message on the view from controller asp.net mvc 5
body: <p>I am new to web development and trying to learn ASP.Net MVC 5. I am looking for one record in database if the record is not found then I want to display an error message to the user. Below is my attempt:</p>
  
  <p><strong>Controller</strong></p>
  
  <pre><code>    [HttpGet]
      public ActionResult Search()
      {
          return View();
      }
  
      [HttpPost]
      [ValidateAntiForgeryToken]
      public ActionResult Search(ForgotPasswordMV viewModel)
      {
          if (Temp.Check(viewModel.Email))
              return RedirectToAction("VerifyToken", new { query = viewModel.Email });
          else
          {
              ViewBag.ErrorMessage = "Email not found or matched";
              return View();
          }
      }
  </code></pre>
  
  <p><strong>View:</strong></p>
  
  <pre><code>&lt;p&gt;@ViewBag.ErrorMessage&lt;/p&gt;
  </code></pre>
  
  <p><strong>ViewModel</strong></p>
  
  <pre><code>public class ForgotPasswordMV
  {
      [Display(Name = "Enter your email"), Required]
      public string Email { get; set; }
  }
  </code></pre>
  
  <p>But I read somewhere that I should put one property in my view model and set the error message on that property. I am confused now, how to achieve that and how to display the error in View then? And which one is the recommended/best practice?</p>