title: asp.net webapi post method returns Object { _body: error, status: 0, ok: false, statusText: "", headers: {…}, type: 3, url: null }
body: <p>I am creating a web api with ef core - code first.</p>
  
  <p>There is a one-to-one relationship of Website to HomeSection, and one-to-many of HomeSection with Paragraph (bridge with HomePara).</p>
  
  <p>Here are my models:</p>
  
  <pre><code>public class Website
  {
      [Key]
      [Required]
      [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
      public int Id { get; set; }
  
      [Required]
      public string Name { get; set; }
      [Required]
      public string WebsiteUrl { get; set; }
  
      public Boolean IsDeleted { get; set; }
  
      public HomeSection Home { get; set; }
  }
  
  public class HomeSection
  {
      public HomeSection()
      {
          HomeParas = new HashSet&lt;HomePara&gt;();
      }
  
      [Key]
      [Required]
      [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
      public int Id { get; set; }
      [Required]
      [MinLength(3)]
      public string Header { get; set; }
      [MinLength(3)]
      public string BackgroundImageUrl { get; set; }
      public Boolean isActive { get; set; }
  
      public ICollection&lt;HomePara&gt; HomeParas { get; set; }
  
      public int WebsiteId { get; set; }
      [ForeignKey("WebsiteId")]
      public virtual Website website { get; set; }
  }
  
  public class HomePara
  {
      public int Id { get; set; }
      public int HomeId { get; set; }
      public int ParagraphId { get; set; }
  
      public HomeSection Home { get; set; }
      public Paragraph Para { get; set; }
  }
  
  public class Paragraph
  {
      public Paragraph()
      {
          HomeParas = new HashSet&lt;HomePara&gt;();
      }
      [Key]
      [Required]
      [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
      public int Id { get; set; }
      public string Text { get; set; }
  
      public ICollection&lt;HomePara&gt; HomeParas { get; set; }
  }
  </code></pre>
  
  <p>The post method of my Controller:
  When the user create a website, I want to create a homesection and a paragraph by default.</p>
  
  <pre><code>[Produces("application/json")]
  [Route("api/Websites")]
  [EnableCors("AllowAny")]
  public class WebsitesController : Controller
  {
      private readonly WebSiteContext _context;
  
      public WebsitesController(WebSiteContext context)
      {
          _context = context;
      }
  
      [HttpPost]
      public async Task&lt;IActionResult&gt; PostWebsite([FromBody] Website website)
      {
          if (!ModelState.IsValid)
          {
              return BadRequest(ModelState);
          }
          _context.Websites.Add(website);
  
          //create a default paragraph data and add it
          Paragraph newParagraph = new Paragraph()
          {
              Text = "Home Para"
          };
          _context.Paragraphs.Add(newParagraph);
  
          //create a default home data and add it
          HomeSection newhome = new HomeSection()
          {
              Header = website.Name + "Head",
              BackgroundImageUrl = website.Name + "bg url",
              WebsiteId = website.Id,
              isActive = true
          };
          _context.HomeSections.Add(newhome);
  
          //mapping home to para
          newhome.HomeParas.Add(new HomePara()
          {
              HomeId = newhome.Id,
              ParagraphId = newParagraph.Id
          });
  
          await _context.SaveChangesAsync();
          return CreatedAtAction("GetWebsite", new { id = website.Id }, website);
      }
  }
  </code></pre>
  
  <p>This is returning <code>Object { _body: error, status: 0, ok: false, statusText: "", headers: {…}, type: 3, url: null }</code> instead of <code>201 status</code>.</p>
  
  <p>However the data is being saved, which I verified with the <code>get</code> request.</p>
  
  <p><strong>EDIT:</strong>
  I have added the controller definition.</p>
  
  <p>I noticed to peculiar things:</p>
  
  <ol>
  <li>I put the whole code of post method inside a try catch and it executed without any errors. However, after the execution of return statement it is binding the <code>Website</code> property and when it hits the <code>HomeSection</code> of <code>HomePara</code> it fails for some reason is escapes the execution flow, and I get <strong>0 status</strong>.</li>
  <li><p>Secondly, if I copy the original parameter of the post method <code>Website website</code> into another <code>Website</code> like below</p>
  
  <pre><code>Website newWebsite = new Website() { Id = website.Id, Name = website.Name, WebsiteUrl = website.WebsiteUrl };
  </code></pre>
  
  <p>and then pass this <code>newWebsite</code> to <code>CreatedAtAction()</code> method, </p>
  
  <pre><code>return CreatedAtAction("GetWebsite", new { id = website.Id }, newWebsite);
  </code></pre>
  
  <p>then I get the <strong>201 status</strong>. I don't know why this happens. How to solve this?</p></li>
  </ol>