title: How to show error message to user in MVC calling Web API?
body: <p>I am working on a MVC Web App which is calling a Web API. In my Create (<code>POST</code>) method, a user will enter email addresses of some users in the database. I have a check to enter the email only if the email does not already exist in the database or not. If it already exists, I want to be able to show an error message to the user "<em>Email already exists</em>". </p>
  
  <p>I thought <code>HttpStatusCode.NotFound, "Email exists already."</code> would work, but I think it will only show in PostMan. How can I show it on the MVC side with like <code>ViewBag.ErrorMessage</code>?</p>
  
  <p><strong>API</strong></p>
  
  <pre><code>public IHttpActionResult PostApprovedUsers(ApprovedUsers approvedUsers)
  {
      if (!ModelState.IsValid)
      {
          return BadRequest(ModelState);
      }
  
  if (!db.ApprovedUsers.Any(u =&gt; u.Email == approvedUsers.Email))
  {
      db.ApprovedUsers.Add(approvedUsers);
      db.SaveChanges();
  }
  else
  {
      return Content(HttpStatusCode.NotFound, "Email exists already.");
  }
  return CreatedAtRoute("DefaultApi", new { id = approvedUsers.Email }, approvedUsers);
  </code></pre>
  
  <p><strong>MVC Create</strong></p>
  
  <pre><code>public ActionResult Create([Bind(Include = "Email,FirstName,LastName")] ApprovedUsers approvedUsers)
  {
      using (WebClient client = new WebClient())
      {
          token = Session.GetDataFromSession&lt;string&gt;("access_token");
              client.Headers.Add("authorization", "Bearer " + token);
              client.UploadValues(apiUrl, "POST", new NameValueCollection()
              {                      
                  { "Email", approvedUsers.Email },
                  { "FirstName",approvedUsers.FirstName },
                  { "LastName",approvedUsers.LastName }
              });                
      }
      return RedirectToAction("Index");
  }
  </code></pre>