是否可以强制@
Html.ActionLink()执行POST而不是GET?如果是这样,怎么样?
解决方法
ActionLink帮助器方法将呈现一个锚标记,单击它始终是一个GET请求.如果你想让它成为一个POST请求.你应该使用一点javacsript覆盖默认的behvIoUr
- @ActionLink("Delete","Delete","Item",new {@id=4},new { @class="postLink"})
现在一些jQuery代码
- <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类型的Action方法来处理此请求
- [HttpPost]
- public ActionResult Delete(int id)
- {
- // do something awesome here and return something
- }