0

我无法通过asp.net mvc submitForm() 中的actionlink 按钮调用javascript 函数是我的函数我的代码是-:

 <script type="text/javascript">
        function submitForm(state) {

           if (state != "") {
                var ele = document.frmuser.elements;
                var strvalue = "";

                for (var i = 0; i < ele.length; i++) {

                    if (ele[i].type == "checkbox") {
                        if (ele[i].name == "chkactive[]") {
                            if (ele[i].checked == true) {
                                //var a = ele[i].value; alert(a);
                                if (strvalue != "")
                                    strvalue = strvalue + "," + ele[i].value;
                                else
                                    strvalue = ele[i].value;

                            }
                        }
                    }
                }
                alert(strvalue);
                    if(strvalue != "" && state !="")
                    {
                        //alert(strvalue);
                        if (state == "active") {
                            location.href = '<%=Url.Action("Deletechkuser")%>' + '/' + $('select[name=chkactive[]]').val();
                        }
                        if(state == "deactive")
                        {
                            location.href = '<%: Url.Action("Deletechkuser", "Home" )%>doctors/updateStatus/' + strvalue + '/is_active/N/' + document.getElementById('hdcurpage').value + '/' + document.getElementById('hdsortkey').value + '/' + document.getElementById('hdsortdir').value;
                        }
                        if(state == "delete")
                        {
                            location.href = '<%: Url.Action("Deletechkuser", "Home" )%>' + strvalue + '/is_deleted/Y/' + document.getElementById('hdcurpage').value + '/' + document.getElementById('hdsortkey').value + '/' + document.getElementById('hdsortdir').value;
                        }
                    }
                    else
                        {
                        alert('Please Select Atleast One Record');
                        document.getElementById("actions").options[0].selected=true;        
                        }
            }
        }
    </script>

上面的代码是我的javascript函数,现在我想传递所有在strvalue中计数的选择值进入控制器我是什么我不知道,我无法submitForm()在按钮单击时调用函数

我的按钮代码是-:

<button class="deletebutton radius3"  id="delete" onclick="location.href='<%: Url.Action("Deletechkuser", "Home", new { id= submitForm(this.id);} )%>'">
          delete</button> 
4

1 回答 1

0

我无法得到这条线:

我想传递所有在strvalue中计数的选择值进入控制器我是什么我不知道

如果您要在单击 ActionLink 时调用该javascript函数,您应该订阅该onclick事件。

@Html.ActionLink("Link Text","ActionName","ControllerName",new { @onclick="MyFunction();" },null)

这是脚本:

<script type="text/javascript">
    function MyFunction(){
        //Do something
        alert('Hello world');
    }
</script>

希望能帮助到你。

于 2013-02-14T09:40:08.270 回答