我想有条件地使用 Html.BeginForm。代码中有2个字段如下
@using (Html.BeginForm("Form1Action", "Form1", FormMethod.Post, new { id = "form1" }))
{
<label for="firstlabel">Label 1</label>
<input type="text" id="firstlabel" name="firstlabel"/>
<label for="secondlabel">Label 2</label>
<input type="text" id="secondlabel" name="secondlabel"/>
<a href="#" class="button" onclick="SubmitForm();">Submit</a>
}
和 JS 是
<script type="text/javascript">
function SubmitForm() {
$('#form1').submit();
}
</script>
如果 secondlabel 为空白或为空,那么我想通过另一个操作提交表单,那么我该如何实现呢?
通过另一个动作,我的意思是:
@using (Html.BeginForm("Form2Action", "Form2", FormMethod.Post, new { id = "form2" }))