ASP.Net MVC,使用JavaScript提交一个表单 [英] ASP.Net MVC, Submit a form using javascript
本文介绍了ASP.Net MVC,使用JavaScript提交一个表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个表格上,我用下面的code创建了我的ASP.Net MVC的景色之一
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))
使用这个code我管不着,据我所知设置窗体的名称。我现在想写一个JavaScript函数提交表单,这可能不知道的形式叫什么名字?
Using this code I have no control as far as I am aware of setting the name of the form. I'm now trying to write a javascript function to submit the form, is this possible without knowing the forms name?
感谢
推荐答案
您可以使用jQuery提交表单:
You can use jquery to submit the form:
<% using (Html.BeginForm(null, null, FormMethod.Post, new { id = "myForm"})) { %>
(最后部分为htmlAttributes参数)
(the last part is for htmlAttributes parameter)
只是这样做:
$("#myForm").submit();
和不要忘了包括jQuery的-1.2.6.js的自带的MVC(或使用更高版本)。
and do not forget to include jquery-1.2.6.js that comes with mvc (or use a higher version).
这篇关于ASP.Net MVC,使用JavaScript提交一个表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文