在剑道脚本标签内提交表单



我在.cshtml文件中有下面的代码,我正在尝试导航到AccountController的HttpPostIndex操作方法,点击锚标记(在最后一个表数据部分中(。但由于某些原因,我无法导航到HttpPost Index Action方法,但当包含在脚本标记之外时,相同的代码可以很好地工作。

<script id="ds-list-tpl" type="text/x-kendo-template">
<tr>                                
<td data-label="Online Store">#: Name #</td>
<td data-label="Phone">#: phone #</td>
<td data-label="Connect">
<span style="display:none;">#: Id #</span>
<form class="hl-form" asp-controller="Account" asp-action="Index" id="introduce-me-form" method="post">
<a href="@Url.Action("Index", "Account")" data-form-method="post" id="introduce-me-button" class="btn-primary">@Localizer["Connect"]</a>
</form>
</td>
</tr>
</script>

And below is the JS code I have written to submit the form 

<script>
$('a[data-form-method='post']').click(function (event) {
event.preventDefault();
$('#introduce-me-button').attr('disabled', 'disabled');
var element = $(this);
var action = element.attr('href');
element.closest('form').each(function () {
var form = $(this);
form.attr('action', action);
form.submit();
});
});
</script>

I am new to Kendo , could somebody please help me on this .
Thank you 

尝试将事件绑定更改为:

$(document).on('click', 'a[data-form-method="post"]', function (event) {

您的表可能是在事件绑定后呈现的。但是,由于将事件直接绑定到尚未呈现的a标记,因此不会绑定任何事件。当您为任何a将事件委派绑定到document时,将考虑到任何已经存在的a,或者将来将在文档中创建。

最新更新