简体   繁体   English

MVC C#使用jquery提交隐藏表单

[英]MVC C# Submit hidden form using jquery

Multiple forms submit with C# MVC. 使用C#MVC提交多个表单。

The company I work for has taken the approach of having multiple forms submits being done using jquery submitting different forms on different button clicks. 我工作的公司采用了通过jquery在不同的按钮单击上提交不同的表单来完成多个表单提交的方法。 My concept should be pretty simple. 我的概念应该很简单。 I have a text box sitting in a form that holds the quantity of items to purchase. 我有一个文本框,它以一种形式保存着要购买的物品数量。 I have two separate buttons, one for adding to cart and one for adding to wish list. 我有两个单独的按钮,一个用于添加到购物车,一个用于添加到愿望清单。 The jquery submits the form, but the formcollection in the MVC code does not have any form data. jQuery提交表单,但是MVC代码中的formcollection没有任何表单数据。

Is My jquery not submitting the form? 我的jQuery不提交表单吗? Or not submitting the hidden fields? 还是不提交隐藏字段?

if you are sure form is submitted then i suppose there is some problem in the view. 如果您确定表单已提交,那么我认为视图中存在一些问题。 all inputs should be submitted for sure, even if they are not visible (eg style="display:none;"). 即使看不见,也应确保所有输入都已提交(例如style =“ display:none;”)。 i could be more specific if i would see the view. 我可以更具体一点,如果我能看到风景的话。

Check the Action signature in the Controller and be sure that you're using the right parameters' name. 检查Controller中的Action签名,并确保使用正确的参数名称。

Just for curiosity, why you're not using ajax for this ? 出于好奇,为什么不为此使用ajax? (@Html.BeginAjaxForm () ) (@ Html.BeginAjaxForm())

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM