【问题标题】:Submitting form inside Kendo Script Tag在 Kendo Script Tag 中提交表单
【发布时间】:2021-06-08 19:26:46
【问题描述】:

我在 .cshtml 文件中有以下代码,我正在尝试导航到 Account 控制器的 HttpPost Index 操作方法,单击锚标记(在最后一个表内数据部分)。但由于某种原因,我无法导航到 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 

【问题讨论】:

    标签: javascript jquery model-view-controller kendo-ui form-submit


    【解决方案1】:

    尝试将您的事件绑定更改为:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-08
      • 1970-01-01
      相关资源
      最近更新 更多