Request url is not found

后端 未结 1 1176
攒了一身酷
攒了一身酷 2021-01-23 16:49

I do this:

http://localhost:53072/Employee/Delete/2

Thats my action:

[HttpPost]
        public ActionResult Delete(int id)
             


        
1条回答
  •  清歌不尽
    2021-01-23 17:17

    Assuming you are accessing the url via a browser it will make a GET request and your action is a POST.

    You could either change your request using a tool like fiddler or change your method to this instead:

        [HttpGet]
        public ActionResult Delete(int id)
        {
            _provider.Delete(id);
            return View();
        }
    

    You could also omit the [HttpGet] as it is the default.

    Update

    In order to make this a post instead of using an ActionLink you could do the following:

    Add this to your view, wrapping it in a begin form

    @using(Html.BeginForm("Delete", "Controller", FormMethod.Post))
    {
        @Html.HiddenFor(m => m.Id)
        
    }
    

    Leave your action as follows:

        [HttpPost]
        public ActionResult Delete(int id)
        {
            _provider.Delete(id);
            return View();
        }
    

    0 讨论(0)
提交回复
热议问题