MVC Html.ActionLink with post funtionality?

Posted by Levitikon on Stack Overflow See other posts from Stack Overflow or by Levitikon
Published on 2011-12-13T20:26:18Z Indexed on 2012/10/28 17:01 UTC
Read the original article Hit count: 223

Filed under:
|
|
|

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" }); %>

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>

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. Thanks!

© Stack Overflow or respective owner

Related posts about c#

Related posts about asp.net-mvc