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).