更新时间:2022-11-27 22:09:13
ActionLink的
helper方法将呈现一个锚
标签,点击这始终是一个 GET
请求。如果你想成为一个 POST
请求。你应该用一个小javacsript覆盖缺省behviour
ActionLink
helper method will render an anchor
tag, clicking on which is always a GET
request. If you want to make it a POST
request. You should override the default behviour using a little javacsript
@ActionLink("Delete","Delete","Item",new {@id=4},new { @class="postLink"})
现在一些的jQuery
code
<script type="text/javascript">
$(function(){
$("a.postLink").click(function(e){
e.preventDefault();
$.post($(this).attr("href"),function(data){
// got the result in data variable. do whatever you want now
//may be reload the page
});
});
});
</script>
请确保您有 HttpPost
的动作
方法类型来处理这个请求
Make sure you have an Action
method of HttpPost
type to handle this request
[HttpPost]
public ActionResult Delete(int id)
{
//do soome thing awesome here and return something
}