使用Html.运行时BeginForm
use Html.BeginForm at runtime
我想使用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" }))
试试这个…
function SubmitForm() {
if($('#secondlabel').val().length)
$('#form1').submit();
else
$('#form2').submit();
}
或通过改变动作
function SubmitForm() {
if($('#secondlabel').val().length == 0)
$('#form1').attr('action', $('#form2').attr('action'));
$('#form1').submit();
}
相关文章:
- 使用压缩的JavaScript文件(不是运行时压缩)
- 如何在运行时在angular 2中加载外部js脚本
- JavaScript错误:Microsoft JScript运行时错误:应为对象
- Google 脚本:用于创建日历活动的脚本运行时不会出错,但不会执行任何操作
- http.listen()在运行时接受终端命令
- 自定义运行时Can'在谷歌应用引擎中看不到我的自定义日志
- 实现比较方法的最佳实践是什么;s的比较类型是在运行时选择的
- JavaScript运行时是如何工作的
- 在运行时创建元素时移到一边时出错
- 如何在运行时在HTML5画布中绘制正方形
- 如何在运行时使用javascript隐藏图像
- 在运行时使用jquery准备表体会导致设计问题
- 使用主题运行时portlet liferay时出现Javascript错误
- JavaScript运行时事件循环现有技术
- Appcelerator Titanium:在运行时下载并解释JavaScript代码
- angularjs ng点击运行时标记不起作用
- 在函数运行时显示对话
- 如何在javascript中在运行时获取对象/数组
- 变量在运行时未定义,但在使用调试器时定义
- 使用Html.运行时BeginForm