title: Multibutton form doesn't map data back to textboxes .net core 1.1
body: <p>Ok, so now I'm trying to learn .net core mcv and I'm having a problem mapping data from MySQL back to my form. When I make the form as a single text box with a single button, and the other fields outside the form (but on the same page), the mapping works fine. If I include all the fields within the form, the data is obtained but not displayed on the page. I have even gone so far as to code one of the multiple submit buttons as an update of the data. I use the first text box to get the item from the database, which it does (but does not map to the text-boxes), then in the second text box (which should have the existing data, but is empty) I put the information to update in the database, click on the submit button for that text box, and the database is updated (but the text boxes in the view remain blank).</p>
  
  <p>My model:</p>
  
  <pre><code> using System;
  
  namespace DbTest.Models
  {
  public class ProductInventory
      {
           public string Field1 { get; set; }
           public string Field2 { get; set; }
           public string Field3 { get; set; }
           public int Field4 { get; set; }
      }
  }
  </code></pre>
  
  <p>my controller:</p>
  
  <pre><code>using System;
  using Microsoft.AspNetCore.Mvc;
  using MySql.Data.MySqlClient;
  using Microsoft.AspNetCore.Authorization;
  
  using DbTest.Models;
  
  namespace DbTest.Controllers
  {
      public class InventoryController : Controller
      {
  //        [Authorize]
          public IActionResult Index()
          {
              return View();
          }
  
          [HttpPost]
          public IActionResult ProcessForm(string button, ProductInventory p)
          {
              IActionResult toDo = null;
  
              if (button == "Button1")
              {
                  toDo = GetItem(p);
              }
              if (button == "Button2")
              {
                  toDo = UpdateField2(p);
              }
              if (button == "Button3")
              {
                  toDo = UpdateField3(p);
              }
              if (button == "Button4")
              {
                  toDo = UpdateField4(p);
              }
  
              return toDo;
          }
  
  //        [HttpPost]
          public IActionResult GetItem(ProductInventory p)
          {
      //CODE SNIP - DATABASE QUERY, IT ALL WORKS, SO WHY BOTHER YOU WITH THE DETAILS?
          return View("Index", p);
          }
  
          public IActionResult UpdateField2(ProductInventory p)
          {
        //CODE SNIP - DATABASE UPDATE, ALL WORKS, NOTHING TO SEE HERE
          return View("Index", p);
          }
      }
  }
  </code></pre>
  
  <p>And finally, my view:</p>
  
  <pre><code>@model DbTest.Models.ProductInventory
  
  @{
      ViewData["Title"] = "Inventory Page";
  }
  
  @using (Html.BeginForm("ProcessForm", "Inventory", FormMethod.Post))
  {
          &lt;div&gt;
              Search Item (Field 1): 
              @Html.TextBoxFor(model =&gt; model.Field1)
              &lt;input type="submit" name="button" value="Button1" /&gt;
          &lt;/div&gt;
          &lt;div&gt;
              Field 2: 
              @Html.TextBoxFor(model =&gt; model.Field2)
              &lt;input type="submit" name="button" value="Button2" /&gt;
          &lt;/div&gt;
          &lt;div&gt;
              Field 3: 
              @Html.TextBoxFor(model =&gt; model.Field3)
              &lt;input type="submit" name="button" value="Button3" /&gt;
          &lt;/div&gt;
          &lt;div&gt;
              Field 4: 
              @Html.TextBoxFor(model =&gt; model.Field4)
              &lt;input type="submit"  name="button" value="Button4" /&gt;
          &lt;/div&gt;
  }
  </code></pre>
  
  <p>To reiterate, if I close the form after Button1:</p>
  
  <pre><code>@using (Html.BeginForm("ProcessForm", "Inventory", FormMethod.Post))
  {
          &lt;div&gt;
              Search Item (Field 1): 
              @Html.TextBoxFor(model =&gt; model.Field1)
              &lt;input type="submit" name="button" value="Button1" /&gt;
          &lt;/div&gt;
  }
          &lt;div&gt;
              Field 2: 
  //etc.
  </code></pre>
  
  <p>the mapping works, but only the first field and button of the form work. With the form around all four fields and buttons, the mapping doesn't work, but the coding of the second button DOES update the database on clicking Button2.</p>
  
  <p>Can someone explain what I've done wrong here?</p>
  
  <p>Thanks!</p>