Как удалить строку из таблицы без обновления страницы? Я удалил представление удаления из представлений, но оно показывает мне «Ресурсы не могут быть найдены» Я не настолько совершенен в MVC, если бы кто-то мог мне помочь с этим, я буду очень благодарен.
[Вот мой индексный просмотр
<table id = "customers">
<tr>
<th style = "text-align:center">
@Html.DisplayNameFor(model => model.Name)
</th>
<th style = "text-align:center">
@Html.DisplayNameFor(model => model.Salary)
</th>
<th style = "text-align:center">
@Html.DisplayNameFor(model => model.Address)
</th>
<th style = "text-align:center">Action</th>
</tr>
@foreach (var item in Model)
{
<tr class = "centerAlign">
<td>
@Html.DisplayFor(modelItem => item.Name)
</td>
<td>
@Html.DisplayFor(modelItem => item.Salary)
</td>
<td>
@Html.DisplayFor(modelItem => item.Address)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id = item.Id }) |
@Html.ActionLink("Details", "Details", new { id = item.Id }) |
@Html.ActionLink("Delete", "Delete", new { id = item.Id })
</td>
</tr>public ActionResult Delete(int id = 0)
{
New_Table new_table = db.New_Table.Find(id);
if (new_table == null)
{
return HttpNotFound();
}
return View(new_table);
}
//
//POST: /Default1/Delete/5
[HttpPost]
public ActionResult Delete(int id)
{
New_Table new_table = db.New_Table.FirstOrDefault(s => s.Id.Equals(id));
if (new_table != null)
{
db.DeleteObject(new_table);
db.SaveChanges();
}
return View("Index");
}] 2



![Безумие обратных вызовов в javascript [JS]](https://i.imgur.com/WsjO6zJb.png)


Надеюсь, это поможет!
Этот код не работал, чего мне не хватает, не могли бы вы уточнить.
Просто используйте для этого JavaScript и Ajax. Попробуйте этот подход в своем DeleteView:
<script>
function DeleteId(id)
{
$.ajax({
dataType: "json",
url: '@Url.Action("ActionName","ControllerName")',
data: {id: id},
success: function(result){
//todo
}
});
}
</script>
<table id = "customers">
<tr>
<th style = "text-align:center">
@Html.DisplayNameFor(model => model.Name)
</th>
<th style = "text-align:center">
@Html.DisplayNameFor(model => model.Salary)
</th>
<th style = "text-align:center">
@Html.DisplayNameFor(model => model.Address)
</th>
<th style = "text-align:center">Action</th>
</tr>
@foreach (var item in Model)
{
<tr class = "centerAlign">
<td>
@Html.DisplayFor(modelItem => item.Name)
</td>
<td>
@Html.DisplayFor(modelItem => item.Salary)
</td>
<td>
@Html.DisplayFor(modelItem => item.Address)
</td>
<td>
<!-- Code Removed for simplicity -->
<a onClick = "DeleteId('@item.Id');"> Delete <a/>
</td>
</tr>
Спасибо за ответ, но это не сработало, я применил этот код.
Вам придется использовать JavaScript и Ajax. Попробуйте поработать с Ajax.ActionLink в Razor View.