// html <% using (Html.BeginForm("MyAction","MyController",new { id = ViewContext.RouteData.Values["id"] },FormMethod.Post,new { enctype = "multipart/form-data",class="myForm" })) { %> <input type="file" name="blah" /> <% } %> // script $container.find('.myButton').click(function() { $container.find('.myForm').submit(); });
在提交表单之前,我需要添加一些额外的参数(路由值),这些参数只能在提交时计算.
我怎么做?
解决方法
您可以在提交之前在表单中附加隐藏字段:
$container.find('.myButton').click(function() { var form = $container.find('.myForm'); form.append( $(document.createElement('input')) .attr('type','hidden') .attr('name','somename') .attr('type','somecalculatedvalue') ); form.submit(); });
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。