I want to use a regular HTML button to call Controller in ASP.NET MVC2 instead of ActionLink, is this possible?
Usually with a button, you will use javascript to call an action or wrap it in a form (or both).
<% Html.BeginForm( "action", "controller", new { id = Model.ID } ) { %> <button type="submit">Go</button> <% } %> <script type="text/javascript"> $(function() { $('button').click( function() { var form = $('form'); $.post( form.attr('action'), form.serialize(), function(msg) { alert(msg); }); return false; // don't really submit the form }); }); </script>
Of course, just use Url.Action()to display the action url.
Url.Action()
<a href="<%= Url.Action("Action") %>">BLA BLA</a>
or
<button onclick="javascript: window.location = '<%= Ajax.JavascriptEncode(Url.Action("Action")) %> '">Click me</button>
<form method="get" action="YourUrl"> <button type="submit">Click me</button> <input type="submit" value="Or click me" /> </form>
, <%= Url.Action(...) %> URL action .
<%= Url.Action(...) %>
action
javascript, , . button , input, , , . .
button
input
Source: https://habr.com/ru/post/1776447/More articles:How is task planning implemented? - javagwt using jquery effect? - javaHow to increment an Integer variable by X without instantiating a new object - ruby | fooobar.comA tool that lists all obsolete classes / methods that are not used anywhere else? - javaWordpress $ wpdb-> usermeta sort by meta_value - wordpressHow to send a request to a stored procedure in MySQL? - mysqlhttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1776449/can-php-be-used-to-make-desktop-application-or-only-make-web-based-application&usg=ALkJrhhmEG2oCguQ3oiuWJ30DJ5R0chg-gПримеры использования Websphere x JSR 286 - javaradio button in jquery ui accordion title makes it not respond - jqueryphp: read attribute from form element - htmlAll Articles