I'm working on a view that presents all the records of class (Machine) where some of their properties could be updated.
For this, the view is working with an IEnumerable. These are the Get and Post methods:
Get Method:
- public async Task
Test() - {
- PopulateMachineTypeDropDownListStore();
- return View(await _context.Machines.AsNoTracking().ToListAsync());
- }
- [HttpPost, ActionName("Test")]
- [ValidateAntiForgeryToken]
- public async Task
TestPost( int id, [Bind("Id,StoreID,PUnit,Status")] Machine machine) - {
- if (id != machine.Id)
- {
- return NotFound();
- }
- if (ModelState.IsValid)
- {
- try
- {
- _context.Update(machine);
- await _context.SaveChangesAsync();
- }
- catch (DbUpdateConcurrencyException)
- {
- if (!MachineExists(machine.Id))
- {
- return NotFound();
- }
- else
- {
- throw;
- }
- }
- return RedirectToAction("Index");
- }
- return View(machine);}

My intention is to update only a few properties of the register thru this view, but for some reason the information from the form is not getting to the Post Method.
Can anyone tell me what is wrong here?
Thanks in advance!
This is the view:
- @model IEnumerable
- @{
- ViewData["Title"] = "Test";
- }
- @foreach (var item in Model)
- {
- asp-route-id="@item.Id" method="post">
-
class="table">
- "hidden" asp-for="@item.Id" />
class="form-group">class="col-md-10">- for="@item.MchName" readonly class="form-control" />
- for="@item.MchName" class="text-danger">
class="form-group">class="col-md-10">- ="@item.StoreID" class="form-control" asp-items="ViewBag.StoreID">
- for="@item.StoreID" class="text-danger">
class="form-group">class="col-md-10">- "number" max="10" step=".1" asp-for="@item.PUnit" class="form-control" />
- for="@item.PUnit" class="text-danger">
class="form-group">class="col-md-10">- asp-for="@item.Status" class="form-control">
- >Operativo
- >Nuevo Item
- >Reparación
- for="@item.Status" class="text-danger">
- "submit-data" type="submit" value="Update" class="btn btn-default" />
- }
Abhilash J APosted Jun 11, 2017, 6:53 AM
Abhilash J APosted Jun 11, 2017, 2:21 AM
nameattribute of controls. Try changingasp-fortonamefor a minute and test.