0
삭제 링크를 클릭하면 내 Student Controller에서 DeleteConfirmed 메서드를 호출하려고합니다.삭제 작업이 호출되지 않습니다.
학생 컨트롤러 코드
[HttpPost, ActionName("Delete")]
public ActionResult DeleteConfirmed(int id)
{
Student student = db.Students.Find(id);
db.Students.Remove(student);
db.SaveChanges();
return RedirectToAction("Index");
}
Index.cshtml 내가 DeleteConfirmed 호출 할 할의 클릭에 대한 링크를 (코드의 마지막 줄) 삭제가 있지만 아래 delete.cshtml이 present.I 돈이 될 것으로 기대
삭제보기를 표시하고 삭제가 asynhronously 일어나길 원합니다.
@model IEnumerable<SMS.Model.Student>
@{
ViewBag.Title = "Student";
}
<h2>Student</h2>
@using (Html.BeginForm()) {
<p>
@Html.ActionLink("Create New", "Create")
</p>
<table>
<tr>
<th>
@Html.DisplayNameFor(model => model.RegistrationNo)
</th>
<th>
@Html.DisplayNameFor(model => model.FirstName)
</th>
<th>
@Html.DisplayNameFor(model => model.MiddleName)
</th>
<th>
@Html.DisplayNameFor(model => model.LastName)
</th>
<th>
@Html.DisplayNameFor(model => model.DateofBirth)
</th>
<th></th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.RegistrationNo)
</td>
<td>
@Html.DisplayFor(modelItem => item.FirstName)
</td>
<td>
@Html.DisplayFor(modelItem => item.MiddleName)
</td>
<td>
@Html.DisplayFor(modelItem => item.LastName)
</td>
<td>
@Html.DisplayFor(modelItem => item.DateofBirth)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id=item.Id }) |
@Html.ActionLink("Details", "Details", new { id=item.Id }) |
@Ajax.ActionLink("Delete", "Delete", new { id = item.Id },new AjaxOptions { HttpMethod = "Post"})
</td>
</tr>
}
} 대신
@using (Html.BeginForm())
의 내부보기
아니요. 작동하지 않습니다. 여전히 그것은 게시물 대신 삭제를 호출하고 오류를 발생시킵니다. 자원을 찾을 수 없습니다. 설명 : HTTP 404. 찾고있는 리소스 (또는 해당 종속성 중 하나)가 제거되었거나 이름이 변경되었거나 일시적으로 사용할 수없는 리소스 일 수 있습니다. 다음 URL을 검토하고 철자가 올바른지 확인하십시오. 요청한 URL :/학생/삭제/5 – Rishikesh
'@Ajax.ActionLink ("삭제", 새로운 {id = item.Id}, 새로운 AjaxOptions {HttpMethod = "게시"}) 액션 위에 ActionName이있는 경우와없는 경우 @Ajax.ActionLink ("Delete", "DeleteConfirmed", 새 {id = item.Id}, 새 AjaxOptions {HttpMethod = "Post"})). –
당신에게 도움이 되었습니까? 감사. –