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 p开发者_Python百科ost). 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 })%>
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" />
<% } %>
精彩评论