MVC Html.ActionLink与岗位功能? [英] MVC Html.ActionLink with post functionality?

查看:152
本文介绍了MVC Html.ActionLink与岗位功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我检查,看是否有人写了一个MVC扩展Html.ActionLink,你可以在帖子参数,如通过这样的:

I'm checking to see if anyone has written an MVC extension for Html.ActionLink that you can pass in Post parameters like such:

<% Html.ActionLink("Click me", "Index", "Home", new { MyRouteValue = "123" }, null, new { postParam1 = "a", postParam2 = "b" }); %>

这会使像正常的链接,但具有提交一个也呈现形式操作URL的行动onClick事件,控制器和路线从邮政的参数,如这些额外的隐藏输入值:

That would render the link like normal but having an onClick event that submits an also rendered form with an Action url for the Action, Controller, and Route Values with additional hidden inputs from the Post Parameters like such:

<a href="#" onClick="$('#theform').submit(); return false;">Click me</a>
<form id="theform" action="/Home/Index/123" method="post">
   <input type="hidden" name="postParam1" value="a">
   <input type="hidden" name="postParam2" value="b">
</form>

我期待将用户重定向到不同的页面,可能会有大量的数据。不仅是从页页,但是从电子邮件到网页也。这将是高度可重用的,我想会清理很多code,并且将节省写这篇如果已经漂浮在那里我一些时间。我讨厌重新创建轮的时候我没有。

I'm looking to redirect users to various pages with potentially a lot of data. Not only from page to page, but from email to page also. This would be highly reusable and I think would clean up a lot of code, and would save a bunch of time writing this if its already floating around out there. I hate recreating the wheel when I don't have to.

推荐答案

ActionLink的仅仅是创建一个&LT; A&GT; 。你所要求的将炸毁,如果它已经是一个形式里面。如果不是那么它是preferable使链接表单内提交按钮无法使用JavaScript(JavaScript和电子邮件不会相处得很好)。

ActionLink is just for creating an <a>. What you are asking for would blow up if it is already inside of a form. If it isn't then it is preferable to make the link the submit button inside the form and NOT use javascript (javascript and emails don't get along great).

您可以创建表格并appende到DOM的末尾。这可以通过局部视图或通过JavaScript来实现。

You could create the form and appende it to the end of the DOM. This could be done through partial view or through javascript.

老实说,我建议你不要使用POST。如果你坚持下去的大部分数据,只需要检索所需的IDS的数据说,你不应该以一种ActionLink的传递太多的数据。

Honestly I suggest you don't use a POST. If you persist most of the data and just have the ids needed to retrieve said data, you should never have to pass too much data in an actionlink.

这篇关于MVC Html.ActionLink与岗位功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆