当提交按钮触发第二个表单时,第二个表单的提交按钮将POST请求发送到原始表单的操作 [英] When a submit button triggers a second form, the second form's submit button sends a POST request to the action of the original form

查看:109
本文介绍了当提交按钮触发第二个表单时,第二个表单的提交按钮将POST请求发送到原始表单的操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在处理MVC表单时遇到麻烦,特别是让表单提交并显示第二个表单.

I've been having trouble with MVC forms, specifically having a form submit and display a second form.

第二个表单的提交"按钮转到原始表单的操作.我问是否可以嵌套表格:为什么要做Asp.net MVC中的嵌套表单没有作用域吗?.由于表单标签确实无法嵌套,因此我进行了更改,因此表单位于单独的div中,以为woudl可以解决问题.

The second form's submit button goes to the action of the original form. I asked if forms could be nested: Why do nested forms in Asp.net mvc not have scope?. Since form tags cannot indeed be nested, I changed things so the forms are in separate divs thinking that woudl resolve the problem.

用户在第一个表单上单击提交"后,将显示第二个表单.当用户单击该表单的提交"按钮时,它将POST到原始表单的控制器操作,而不是以新表单的视图和视图模型命名的控制器.

After the user clicks submit on the first form, the second form appears. When the user clicks on that form's submit button, it POSTs to the controller action of the original form, not the one named after the view and viewmodel of the new form.

正在插入的表单正在使用 Ajax.BeginForm(new AjaxOptions {UpdateTargetId ="X"}))

The form being inserted is using Ajax.BeginForm(new AjaxOptions {UpdateTargetId="X"}))

第二种形式在其末尾具有< input type ="submit"> 标记.再次,当用户单击此按钮时,表单模型中的任何值都不会发送回控制器.

The second form has an <input type="submit"> tag at its end. Again, when the user clicks this button, none of the values in the form's model get sent back to the controller.

我尝试在Ajax链接中明确指定控制器动作:

I've tried explicitly specifying the controller action in the Ajax link:

<%:Ajax.ActionLink(添加操作系统",操作系统",新的AjaxOption {UpdateTargetId =",HttpMethod ="POST"})%>

这会将表单发送回正确的操作.但是,所有发送回的值都为空.

This sends the form back to the correct action. However, all the values being sent back are null.

FormCollection与 Html.BeginForm 并通过解析 FormCollection 字典进行了短暂的合作,但是由于我不完全了解的原因,该设置停止了工作.

FormCollection worked briefly with Html.BeginForm and by parsing the FormCollection dictionary but that setup stopped working for a reason I don't fully understand.

这是什么问题?我觉得我又一次进入了Webform领域...

What is the issue here? I feel like I'm in webform land all over again...

推荐答案

我认为这里的问题是,您试图将两种不同的形式提交给同一操作.通常,当您有两个表单时,将有两个包含字段的不同关联视图模型.因此,我建议您进行两种不同的控制器操作.

I think the problem here is that you are trying to submit two different forms to the same action. Normally when you have two forms you have two different associated view models containing the fields. So I would recommend you having two different controller actions.

这篇关于当提交按钮触发第二个表单时,第二个表单的提交按钮将POST请求发送到原始表单的操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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