asp.net-mvc @Html.ActionLink 调用 Post 方法

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13161645/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 02:22:29  来源:igfitidea点击:

@Html.ActionLink calling Post method

asp.net-mvcpostrazorget

提问by Sachin Kainth

I have a @HTML.ActionLinkin my Razor view and I'd like for it to call a Postaction method rather than a Getone.

@HTML.ActionLink我的 Razor 视图中有一个,我希望它调用一个Post操作方法而不是一个操作方法Get

Is this possible?

这可能吗?

采纳答案by jwaliszko

If you want to invoke POST action, put this link inside form which uses POST action, or use ajax version. You can find some more details here.

如果要调用 POST 操作,请将此链接放在使用 POST 操作的表单中,或使用 ajax 版本。您可以在此处找到更多详细信息。

回答by Liz Nett

If you are using bootstrap you can easily make a button look like a link by applying the btn-link class, for example

例如,如果您使用的是引导程序,则可以通过应用 btn-link 类轻松地使按钮看起来像链接

<input type="submit" name="ActionType" value="Edit" class="col-md-1 btn btn-link" />

回答by René Wolferink

Yes and no. Normal ActionLinks will be normal links. Either you have to use a form (with method being post of coorse) and have a link sumbit it. Or you could add in a but of javascript and a nice extension.

是和否。普通 ActionLink 将是普通链接。要么你必须使用一个表单(方法是 post of coorse)并有一个链接 sumbit 它。或者你可以添加一个 javascript 和一个不错的扩展。

Have a look at http://dr2ab.wordpress.com/2011/07/25/linkbuttons-in-mvc-razor/

看看http://dr2ab.wordpress.com/2011/07/25/linkbuttons-in-mvc-razor/

Might be something for you.

可能适合你。