Hello,
I'm constructing this view where the user can edit multiple item and save one at the time with the 'Update' button.
Right now, when I hit the Update button to save the changes,
1.- It goes to this address: http://localhost:60288/1, where '1' is the ID of the Machine inside the Database and the website is blank
2.- It does not update the register with the changes made :(
I've been struggling with this for days, and I hope I can find some help here.
This is the Put Method:
- [HttpPut("{id}"), ActionName("Test")]
- [ValidateAntiForgeryToken]
- public async Task
TestPost( int id, Machine machinetoUpdate) - {
- if (!ModelState.IsValid)
- {
- return BadRequest(ModelState);
- }
- if (id != machinetoUpdate.Id)
- {
- return BadRequest();
- }
- _context.Entry(machinetoUpdate).State = EntityState.Modified;
- try
- {
- await _context.SaveChangesAsync();
- }
- catch (DbUpdateException)
- {
- ModelState.AddModelError("", "Unable to save changes. " +
- "Try again, and if the problem persists, " +
- "see your system administrator.");
- }
- //PopulateMachineTypeDropDownListStore();
- return View(await _context.Machines.AsNoTracking().ToListAsync());
- }
- public async Task
Test() - {
- PopulateMachineTypeDropDownListStore();
- return View(await _context.Machines.AsNoTracking().ToListAsync());
- }
- @model IEnumerable
- @{
- ViewData["Title"] = "Test";
- }
Management
class="table">
Serial Tienda Precio por Jugada Estado Update - @foreach (var item in Model)
- {
- asp-route-id="@item.Id">
-
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">
- >-- Seleccione Tienda --
- 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" value="Update" class="btn btn-default" />
- }
Regards,
Luis.
Luis Alberto Delgado de la FlorPosted Jun 2, 2017, 2:37 PM
Luis Alberto Delgado de la FlorPosted Jun 2, 2017, 12:35 PM
Zakir AhamedPosted Jun 2, 2017, 6:00 AM
{
string id = GridView1.DataKeys[e.RowIndex].Values["id"].ToString();
string txt_Firstname = ((TextBox)GridView1.Rows[e.RowIndex].Cells[1].Controls[0]).Text;
string txt_Mobilenumber = ((TextBox)GridView1.Rows[e.RowIndex].Cells[3].Controls[0]).Text;
string txt_Lastname = ((TextBox)GridView1.Rows[e.RowIndex].Cells[2].Controls[0]).Text;
string txt_Email = ((TextBox)GridView1.Rows[e.RowIndex].Cells[4].Controls[0]).Text;
con.Open();
SqlCommand cmd = new SqlCommand("update login set Firstname='" + txt_Firstname + "', Lastname='" + txt_Lastname + "', email='" + txt_Email + "', mobilenumber='" + txt_Mobilenumber + "' where ID='" +Convert.ToInt32(id)+"'", con);
cmd.ExecuteNonQuery();
con.Close();
GridView1.EditIndex = -1;
BindGrid();
}