TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Luis Alberto Delgado de la Flor
NA
127
23.1k
ASP.NET Core: Data Grid - Problem with Update Operation
Jun 2 2017 1:14 AM
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<IActionResult> 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());
}
And this is the Get Method:
public
async Task<IActionResult> Test()
{
PopulateMachineTypeDropDownListStore();
return
View(await _context.Machines.AsNoTracking().ToListAsync());
}
And this is the View:
@model IEnumerable<Application.Models.Machine>
@{
ViewData[
"Title"
] =
"Test"
;
}
<h2>Management</h2>
<hr />
<table
class
=
"table"
>
<thead>
<tr>
<th>Serial</th>
<th>Tienda</th>
<th>Precio por Jugada</th>
<th>Estado</th>
<th>Update</th>
</tr>
</thead>
</table>
@
foreach
(var item
in
Model)
{
<form asp-action=
"Test"
asp-route-id=
"@item.Id"
>
<table
class
=
"table"
>
<tbody>
<tr>
<td>
<input type=
"hidden"
asp-
for
=
"@item.Id"
/>
<div
class
=
"form-group"
>
<div
class
=
"col-md-10"
>
<input asp-
for
=
"@item.MchName"
readonly
class
=
"form-control"
/>
<span asp-validation-
for
=
"@item.MchName"
class
=
"text-danger"
></span>
</div>
</div>
</td>
<td>
<div
class
=
"form-group"
>
<div
class
=
"col-md-10"
>
<select asp-
for
=
"@item.StoreID"
class
=
"form-control"
asp-items=
"ViewBag.StoreID"
>
<option value=
""
>-- Seleccione Tienda --</option>
</select>
<span asp-validation-
for
=
"@item.StoreID"
class
=
"text-danger"
></span>
</div>
</div>
</td>
<td>
<div
class
=
"form-group"
>
<div
class
=
"col-md-10"
>
<input type=
"number"
max=
"10"
step=
".1"
asp-
for
=
"@item.PUnit"
class
=
"form-control"
/>
<span asp-validation-
for
=
"@item.PUnit"
class
=
"text-danger"
></span>
</div>
</div>
</td>
<td>
<div
class
=
"form-group"
>
<div
class
=
"col-md-10"
>
<select name=
"Status"
asp-
for
=
"@item.Status"
class
=
"form-control"
>
<option value=
"0"
>Operativo</option>
<option value=
"1"
>Nuevo Item</option>
<option value=
"2"
>Reparación</option>
</select>
<span asp-validation-
for
=
"@item.Status"
class
=
"text-danger"
></span>
</div>
</div>
</td>
<td>
<input type=
"submit"
value=
"Update"
class
=
"btn btn-default"
/>
</td>
</tr>
</tbody>
</table>
</form>}
Thanks in advance for any help. If any extra information is needed, please ask.
Regards,
Luis.
Reply
Answers (
3
)
Read Data From Excel File (xls, xlsx) In ASP.NET MVC
ASP.Net MVC: regarding RedirectToAction function