How to use the anchor tag to send when using Html.BeginForm?

How to use anchor tag to send when using Html.BeginForm? The method has BeginFormno way to specify the name of the form so that I can do it

<a href="JAVASCRIPT:Form1.submit()">Next</a>

This does not work because it does not exist Form1.

+3
source share
4 answers

If you are using jQuery, use

<a href="javascript:$('form').submit();">Submit</a>
+14
source

So you add the attribute "name" using the htmlAttributes object

<% using (Html.BeginForm("Action", "Controller", FormMethod.Post, new { name = "MyFormName" }))
+7
source

, :

<a href="javascript:document.getElementsByTagName('form').item(0).submit()">Next</a>
+3

jQuery onclick .closest('form'):

<a href="#" onclick="$(this).closest('form').submit(); return false;">My link</a>
+1

Source: https://habr.com/ru/post/1706291/


All Articles