Dejan.S
Dejan.S

Reputation: 19158

Delete file, my post don't work?

I got a view where I list files and I got a Delete button but I got problems the delete act like a link (get instead of post). I can't figure out why. I'm on a view that's called EditFiles so I just want to delete the file and kinda refresh the page. Any thoughts on this?

[AcceptVerbs(HttpVerbs.Post)]
    public ActionResult DeletePicture(string name)
    {
        Do some code here

        _AdminViewModel.Site = _pageBodyService.Get().Where(x => x.BelongSite == "Innergard").SingleOrDefault();
        return View("EditFiles", _AdminViewModel);
    }   


<%= Html.ActionLink("Radera bild", "DeletePicture", new { name = picture.Picture })%>

Upvotes: 0

Views: 233

Answers (1)

Darin Dimitrov
Darin Dimitrov

Reputation: 1039160

Html.ActionLink generates an anchor tag which always performs GET request. In order to perform a POST request you could either use AJAX or an HTML form. Here's an example with HTML form:

<% using (Html.BeginForm(new { action = "DeletePicture", name = picture.Picture })) { %>
    <input type="submit" value="Radera bild" />
<% } %>

Upvotes: 1

Related Questions