如何在提交-MVC,HTML时发送数据以外的数据 [英] how to send data outside form while submitting -MVC ,HTML

查看:77
本文介绍了如何在提交-MVC,HTML时发送数据以外的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


$ b

 <%using(Html.BeginForm(SaveRecords,搜索,FormMethod.Post))
{%>
< input type =submitvalue =Saveclass =button_62title =Save/>
//一些控件
<%}%>

我的需求是在同一个视图中有另一个表单。当点击保存按钮时,我需要获取在表单提交之外的特定文本框的值。我无法将该控件放在同一个表单中。而且我无法使用ajax请求发送数据。无论如何,我可以在提交之前在表单之外追加数据吗?



我想在控制器Saverecords中获得该文本框的值(out sid提交的表单)。

解决方案

这是一个使用javascript的回答



使用jQuery,您可以在上面的表单中设置一个隐藏字段,其中包含与如果您在上面的表单中添加了一个ID,那么。



<$ p $



($(#my $))。()($(#myIndex)。 b $ b});


In my view there is a form shown below

    <% using (Html.BeginForm("SaveRecords", "Search", FormMethod.Post))
                 { %>
                <input type="submit" value="Save" class="button_62" title="Save" />
                 // some controls
                <%} %>

My need is that there is another form in the same view.While clicking save button i need to get value of a particular text box that is outside the form submitting .I cant put that control in same form.And i cant use ajax request to send data. Is there anyway i can append data outside of the form before submitting it?

I want to get value of that textbox(out sid the submitted form) in controller Saverecords ..

解决方案

Here is an answer using javascript

using jQuery you could set a hidden field in the the form above containing the same value as the control that resides in the other form.

if you add an id to your form above then.

$("#myform").submit(function() {
  $("#myhiddenId").val($("#fieldInOtherFormId").val());
});    

这篇关于如何在提交-MVC,HTML时发送数据以外的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆