如何从mvc控制器调用javascript函数 [英] How to call javascript function from mvc controller
本文介绍了如何从mvc控制器调用javascript函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何从asp.net mvc控制器调用javascript函数
解决方案
在视图中,您可以定义表单元素,如输入文本,下拉列表或文本区域,然后定义带有id的按钮,并在脚本中调用click事件,它会将表单数据发送到控制器
@ using (Html.BeginForm(Submitform,myControler,FormMethod.Post,new {@id =form-submit,@ class =form-horizontal container}))
{
---------代码跳过
- 您的表单输入
< div class = col-sm-8 >
< 输入 类型 = 按钮 class = form-control >
< span class = btn btn-success id = btn-submit > 提交< / span >
< span class =code-keyword>< / div >
----代码跳过
}
< script>
('#btn-submit').on('click',function()
{
//如果你想
检查其他条件>
( '形式#形式提交')提交();
});< / script>
希望这会有所帮助
how to call javascript function from asp.net mvc controller
解决方案
In the view you can define form elements such as input text, dropdown or text area and then define the button with an id and in the script call the click event and it will POST your form data to the controller
@using (Html.BeginForm("Submitform", "myControler", FormMethod.Post, new { @id = "form-submit", @class = "form-horizontal container"})) { ---------code skipped --your form inputs <div class="col-sm-8"> <input type="button" class="form-control"> <span class="btn btn-success " id="btn-submit">submit</span> </div> ----code skipped }
<script>
('#btn-submit').on('click', function () { //check other condition here if you would like to
('form#form-submit').submit(); });</script>
Hope this will help
这篇关于如何从mvc控制器调用javascript函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文