当提交按钮触发第二个表单时,第二个表单的提交按钮会向原始表单的操作发送 POST 请求
我在使用 MVC 表单时遇到了问题,特别是提交表单并显示第二个表单。
第二个表单的提交按钮将转到原始表单的操作。 我问表单是否可以嵌套:为什么Asp.net mvc 中的嵌套表单没有范围?。由于表单标签确实不能嵌套,我改变了一些东西,使表单位于单独的 div 中,认为可以解决问题。
用户单击第一个表单上的“提交”后,将出现第二个表单。当用户单击该表单的提交按钮时,它会 POST 到原始表单的控制器操作,而不是以新表单的视图和视图模型命名的控制器操作。
正在插入的表格正在使用 Ajax.BeginForm(new AjaxOptions {UpdateTargetId="X"}))
第二个表单末尾有一个 标记。同样,当用户单击此按钮时,表单模型中的任何值都不会发送回控制器。
我尝试在 Ajax 链接中显式指定控制器操作:
<%: Ajax.ActionLink("Add OS","OS",new AjaxOption{UpdateTargetId="", HttpMethod="POST"})% >
这会将表单发送回正确的操作。然而,所有发回的值都是空的。
FormCollection 与 Html.BeginForm
一起短暂工作,并通过解析 FormCollection
字典,但该设置因我不完全理解的原因而停止工作。
这里有什么问题呢?我感觉我又回到了网络形式的世界......
I've been having trouble with MVC forms, specifically having a form submit and display a second form.
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.
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.
The form being inserted is usingAjax.BeginForm(new AjaxOptions {UpdateTargetId="X"}))
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.
I've tried explicitly specifying the controller action in the Ajax link:
<%: Ajax.ActionLink("Add OS","OS",new AjaxOption{UpdateTargetId="", HttpMethod="POST"})%>
This sends the form back to the correct action. However, all the values being sent back are null.
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.
What is the issue here? I feel like I'm in webform land all over again...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为这里的问题是您试图向同一操作提交两个不同的表单。通常,当您有两个表单时,您有两个不同的包含字段的关联视图模型。所以我建议您使用两种不同的控制器操作。
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.