使用 RenderAction 提交多个表单
我正在使用 RenderAction 将下面的表单包含在我的视图中:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<IEnumerable<SelectListItem>>" %>
<% using (Html.BeginForm("form1", "UserControls", FormMethod.Post, new { @id = "form1" }))
{ %>
<div id="superDiv">Super User | Account: <%= Html.DropDownList("dropdown", Model)%>
<button type="submit" class="button">Button</button>
</div>
<% } %>
问题是,当我在视图中有表单时,例如:
<% using (Html.BeginForm("Reports", "Report", FormMethod.Post, new { @id = "reportForm", style= "display:none" }))
{ %>
<%: Html.AntiForgeryToken()%>
<%: Html.Hidden("reportType", null, new { @id = "reportType" }) %>
<div class="middle"><button type="submit" class="button">Generate Report</button>
<% } %>
它将自动从 RenderAction 提交表单,如何防止这种情况发生?
I am using RenderAction
to include the form below in my views:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<IEnumerable<SelectListItem>>" %>
<% using (Html.BeginForm("form1", "UserControls", FormMethod.Post, new { @id = "form1" }))
{ %>
<div id="superDiv">Super User | Account: <%= Html.DropDownList("dropdown", Model)%>
<button type="submit" class="button">Button</button>
</div>
<% } %>
The problem is that when I have a form in a view eg:
<% using (Html.BeginForm("Reports", "Report", FormMethod.Post, new { @id = "reportForm", style= "display:none" }))
{ %>
<%: Html.AntiForgeryToken()%>
<%: Html.Hidden("reportType", null, new { @id = "reportType" }) %>
<div class="middle"><button type="submit" class="button">Generate Report</button>
<% } %>
It will auto submit the form from RenderAction
, how can this be prevented?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许你应该使用
Partial
而不是RenderAction
我用它来处理 1 页上的两个表单(带有 2 个提交按钮):
第一个视图
第二个视图
第三个主视图:
更新:
我需要将数据加载到用户控件中,并在多个视图/控件上使用它。它如何与部分一起工作?
您可以创建
Helper
来接受您的数据/参数并通过部分视图呈现,然后您可以在视图中使用它(类似的东西):
Maybe you should use
Partial
instead ofRenderAction
I use it to handle two forms (with 2 submit-buttons) on 1 page:
1st view
2nd view
3rd main view:
upd:
I need to load data into the user control, and use it on multiple views/controls. How does that work with partial?
You can create
Helper
that will accepts your data/params and renders by partial viewsthen you can use it in your views (something like that):