delete operation - asp.net mvc - general feedback - styling issue
It is bad practise to perform a delete operation via get request so I have implemented a delete 'post' as asp.net mvc does only support post + get requests (as far as I know).
Please note that I try to avoid javascript/jquery where I could easily perform delete requests (even puts).
I have placed forms on the page for each delete of an item. I have also managed to style the post/submit button to look like a link but things are still not looking very nice. The delete ‘link’ is slightly offset. This is roughly the code:
<% using (Html.BeginForm("Deletex", "xs", FormMethod.Post, new { @class = "deleteForm" }))
{ %>
<%= x.Name %>
<%= Html.Hidden("Id", x.Id)%>
<input type="submit" value="Delete" class="link_button" />
<% } %>
And this is the CSS
.link_button
{
background-color:white;
border:0;
color:#034af3;
text-decoration:underline;
font-size:1em;
font-family:inherit;
cursor:pointer;
float:left;
margin:0;
padding:0;
}
.deleteForm
{
float:right;
margin:0;
padding:0;
}
Did somone else style this succesfully?
Do you have any further feedback reag开发者_运维问答arding delete ‘posts’ and asp.mvc?
Is this the right way to do things?
Thanks.
Best wishes,
Christian
Cannot help you about styling, just a little clarification about the HTTP verbs. ASP.NET MVC supports all the verbs GET, POST, PUT, DELETE - the problem comes from most browsers that only support GET and POST. You could simulate them using the HttpMethodOverride helper:
<%= Html.HttpMethodOverride(HttpVerbs.Delete) %>
and in your controller action:
[HttpDelete]
public ActionResult Destroy(int id)
{
return View();
}
精彩评论