ASP.Net MVC, Submit a form using javascript

前端 未结 5 1069
时光取名叫无心
时光取名叫无心 2020-12-29 20:14

I have a form on one of my ASP.Net MVC views that I created using the following code

 <% using (Html.BeginForm(null, null, FormMethod.Post))
5条回答
  •  轮回少年
    2020-12-29 20:43

    If you want to use jQuery without naming the form, and you will only have one form on the page, you can just add a link like this to your page:

    Submit
    

    And then add this jQuery which will wire up the link to submit every form:

    $(document).ready(function () {
        $("a.submitForm").click(function () {
            $("form").submit();
        });
    });
    

    So this is a way of doing it (the way I just did it on my site) that doesn't require you to name the form - provided you only have one. Saying that, you may want to submit multiple forms ..

提交回复
热议问题