2013-02-14 39 views
0

調用javascript函數我不能夠通過ActionLink的按鈕來調用javascript函數在asp.net mvc的 submitForm()是我的函數 我的代碼是 - :如何通過ActionLink的

<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> 

回答

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> 

希望它能幫助。