2016-11-22 160 views
0

儘量避免使用屬性disabled提交按鈕點擊多次提交,但點擊它只是阻止按鈕,沒有任何反應。嘗試添加id到Html.Begin形式,而是點擊它給服務器應用程序錯誤,如:the parameters dictionary contains a null entry for parameter 'id' of non-nullable type System.Int32提交表單上的阻止按鈕

@using (Html.BeginForm(MVC.Controller.MethodName(), FormMethod.Post, new { id = "submitFormId" })) 


<button class="btn btn-w-m btn-primary" type="button" id="submitButtonId" value="AddSmth" onclick="return validateForm(event)"> 
    <i class="fa fa-plus"></i>&nbsp;Add 
</button> 

和JS:

$("#submitButtonId").attr("disabled",true); 
$('#submitFormId').submit(); 
+1

http://stackoverflow.com/questions/926816/how-to-prevent-從提交的多次客戶端 –

+1

@mplungjan不適合我 – Vitaliy

回答

0

創建另一種方法來防止多次點擊按鈕。只是說:

@{ Html.EnableClientValidation(); } 
@{ Html.EnableUnobtrusiveJavaScript(); } 

要將視圖,並添加全局變量var isSubmited = false;後,再通過驗證它:

if (isSubmited) e.PreventDefault(); 

. . . 

if ($('#submitFormId').valid()) { 
      isSubmited = true; 
     } 
0

該proplem是你想要在你的URL的id參數但你不提供一個。前面的例子:

https://example.com/controller/edit/1 
            ^^ missing 

1(id)缺失。

+0

它的奇怪,因爲從方法控制器提交我收到的模型,而不是id – Vitaliy

+0

你試過從丹麥cmt? – manuzi1

0

,因爲當你按下按鈕時重新加載頁面,以便禁止屬性被刪除

如果要設置這個條件,然後用ajax使頁面不會被重新裝入,然後按鈕禁用是這是不可能的也正在工作

+0

嗯,我不能使用Ajax,因爲我在這個視圖上上傳文件。我知道ajax不能使用文件,對嗎? – Vitaliy

+0

ajax使用文件也 –

+0

check thi https://www.formget.com/ajax-image-upload-php/ –