I have client side validations of java script and model state validations in controller, related to file attachment. I want to disable my save (submit) button once it clicked. I have checked all solution given at stack overflow links related to this.
$(document).ready(function () {
$(".submitBtn").click(function () {
$('input[type="submit"]').prop('disabled',true);
$('#yourFormId').submit();
});
});
MVC
public actionresult Save(LatestUpdatemaster objUpdate,HttppostedFileBase filename){
string strResult="";
strResult = Utility.UploadUpdateDocument(filename,foldername);
if(strResult != "1"){
ModelState.AddModelError("FileName",strResult);
}
else{
//Save code...
}
}
Also tried this,
$('#form').one('submit',function(){ $(this).find('input[type="submit"]).attr('onclick','his.style.opacity="0.6";return false;');
Code Creating Button
<input class="btn btn-primary" type="submit" value="Save" name="Save" id="Save" />
Client Side - View
$('#Save').click(function(e){
Duplicatevalidation();
if($'#Updatename').text().trim() == ''){
e.preventDefault();
}
});
If I do it client side then values won't submit to controller. Also I want server side model validation completed and then make it disable for not submitting form twice. Please guide.
You can simply do this
$(document).ready(function () {
$(".submitBtn").click(function () {
$(this).prop('disabled',true);
$('#yourFormId').submit();
});
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.