locked
Confirm delete RRS feed

  • Question

  • User-285756856 posted

    I want to add a confirm delete in delete method. i use form and it work but i want to use actionlink to make a confirm. it show alert but when i click 'yes' option then nothing happend. Please help.

    this code use form

    @using (Html.BeginForm())
    {
    @Html.AntiForgeryToken()
    <div class="form-actions no-color">
    <input class="btn btn-default" type="submit" value="Delete" onclick="return confirm('Are you sure you want to delete?')" />
    @Html.ActionLink("Back to List", "Index")
    </div>
    }

    and it's action link

    @Html.ActionLink(
    "Delete",
    "Delete",
    "Product",
    new { id = Model.MaSP },
    new { onclick = "return confirm('Are you sure you wish to delete this article?');" })

    Wednesday, May 2, 2018 3:15 AM

Answers

  • User-369506445 posted

    hi

    it's correct when use submit button it's well but when use actionlink you get exception.

    because your action is using HttpPost ,that work for submit but not work with actionlink,if you change HttpPost to HttpGet your problem will be solved

      [HttpGet]
            public ActionResult Delete(int id)
            {

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, May 2, 2018 5:03 AM

All replies

  • User-369506445 posted

    hi

    it's correct when use submit button it's well but when use actionlink you get exception.

    because your action is using HttpPost ,that work for submit but not work with actionlink,if you change HttpPost to HttpGet your problem will be solved

      [HttpGet]
            public ActionResult Delete(int id)
            {

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, May 2, 2018 5:03 AM
  • User-285756856 posted

    Thanks. It's work

    Wednesday, May 2, 2018 5:42 AM