tags:

views:

27

answers:

1

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 })%>
+1  A: 

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" />
<% } %>
Darin Dimitrov
thanks thanks darin i was lookng for a solution for this..
Jasl
Thanks I thought it was something with the form. But im gone have like 200 files so thought that there was a way around using a form. I think I'm gone go with the AJAX, but one thing tho the AJAX I don't need the form at all?
Dejan.S
With AJAX you don't need a form. You attach a click handler to the anchor link in which you cancel the default action and call the href asynchronously.
Darin Dimitrov