我在谷歌上搜索了很多关于这个问题的信息,但找不到关于我的场景的任何帮助。那么问题来了
我有一个包含单个下拉列表的表单,名为 Sections,用户可以选择一个Section,然后用户有两个选择。
1-通过转到文件上传表单将文件添加到此部分
2-通过添加部分表格添加更多小节
This is image of my form
@using (Html.BeginForm("SectionForm","Sections"))
{
<div class="form-group">
@Html.DisplayFor(s => s.SectionName)
@Html.DropDownListFor(s => s.SelectedSection, new SelectList(Model.Sections,"SectionId","SectionName"),"Select a Section",new {@class = "form-control",autofocus="autofocus"} )
</div>
<p>
If you don't see your desired section here, Click <strong>Add Section</strong>.
</p>
<button type="submit" class="btn btn-primary">Add Further Subsection</button>
<br />
<a href="@Url.Action("FileForm","LawFiles",new { sectionId = Model.SelectedSection })" class="btn btn-primary">Add File</a>
}
<br>
SectionForm 和 FileForm 是我的操作,Sections 和 LawFiles 是 Controller 。
在我不提交表单之前,末尾的 anchor 标记 将不起作用
最佳答案
您可以使用 javascript 修改表单的操作。您将在提交按钮上添加点击事件并覆盖默认提交操作。
<html>
<body>
<form id="myform">
<input type="submit" id="submit1"/>
<input type="submit" id="submit2"/>
</form>
</body>
<script>
$("#submit1").click(function() {
document.myform.action = “http://localhost/controller/action1”;
});
$("#submit2").click(function() {
document.myform.action = “http://localhost/controller/action2”;
});
</script>
</html>
关于c# - 在两个不同的 Controller asp.net mvc中将表单提交给两个不同的 Action ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38782295/