Reputation: 139
I am using Actionlink and JQuery to submit a form. It is submitting the form every time when clicking the link. I want to submit the form only the first time(once). The code is -
@Html.ActionLink(Model.link, "DefaultRate", "DefaultRate", null, new { @class = "btnclick", onclick = "return false;" })
<script type="text/javascript">
$(document).ready(function () {
$('.btnclick').click(function () {
$(this).closest('form')[0].submit();
});
});
</script>
Thanks in advance
Upvotes: 1
Views: 139
Reputation: 48437
This must work:
@Html.ActionLink(Model.link, "DefaultRate", "DefaultRate", null, new { @class = "btnclick"})
<script type="text/javascript">
$(document).ready(function () {
var allow = true;
$('.btnclick').click(function () {
if (allow){
$(this).closest('form')[0].submit();
allow = false;
}
else
return false;
});
});
</script>
Upvotes: 1
Reputation: 95
Here is what you want
<script type="text/javascript">
$(document).ready(function () {
$('.btnclick').bind("click", function () {
$('.btnclick').unbind("click");
$(this).closest('form')[0].submit();
});
});
</script>
Upvotes: 0