title: Return a 404 in public async Task OnGet(string slug) in Razor Pages if slug does not exist in CMS
body: <p>I have the following Page Model method:</p>
  
  <pre><code>public class CarModel : PageModel
      {
  public Car Car { get; private set; }
  
  public async Task OnGet(string slug)
          {
  
  
  
              var client = clientManager.GetClient();
  
  
              var carPages = await client.GetBySlugAsync();
  
              CarPages= carPages.Items[0];
  
  // if carPages.Items is null, out of range, or if CarPages is null, then return a 404
  
          }
  }
  </code></pre>
  
  <p>Razor Page:</p>
  
  <pre><code>@page "/{slug}"
  @model CarModel
  @{
      ViewData["Title"] = "Some title";
  }
  
  &lt;div&gt;Some markup&lt;/div&gt;
  </code></pre>
  
  <p>If I enter a slug in the browser that does not exist in the CMS then I want the OnGet method to return a 404. How do I do that (best practice example)?</p>
  
  <p>(currently, if I enter a non-existent slug in the browser, hit return, I will get a server error)</p>
  
  <p>Haven't found any example on Microsoft docs for Razor Pages.</p>