开发者

Delete file, my post don't work?

开发者 https://www.devze.com 2023-01-04 20:49 出处:网络
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 E

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" />
<% } %>
0

精彩评论

暂无评论...
验证码 换一张
取 消