简体   繁体   English

回传后,jQuery自动完成不起作用

[英]Jquery Autocomplete not working after postback

In MVC 4, I have a textbox with Autocomplete functionality in a partial view And i am using this partial view in two views,view 1 and View 2.In View 1 ,it is working fine, as view 1 does not have any postback, while in View 2, i have a submit button causing postback,and after this postback,the partial is shown on the screen or else it is hidden.The Autocomplete here is not working. 在MVC 4中,我在部分视图中有一个具有自动完成功能的文本框,并且我在两个视图(视图1和视图2)中使用此部分视图。在视图1中,它工作正常,因为视图1没有任何回发,在View 2中,我有一个提交按钮导致回发,在回发之后,部分显示在屏幕上,否则它被隐藏了。此处的自动完成功能不起作用。

$("#txtProduct").autocomplete({
            source: function (request, response) {
                $.ajax({
                    type: "POST",
                    data: { term: request.term },
                    datatype: JSON,
                    url: 'UploadEligibilityCodes/GetAllMatchingProducts',
                    success: function (data) {

                        response($.map(data, function (value, key) {
                            return {
                                label: value.ProductName.concat("(", value.ProductId, ")"),
                                value: value.ProductName,
                                pid: value.ProductId
                            };
                        }))
                    }

                });
            },
            select: function (event, ui) {
                $('#hdnProductIdSearch').val(ui.item.pid);

            }
        });

This is the code of my text box defined in Partial view named SearchFilters.cshtml and View 2 which uses this partial view as follows. 这是在名为SearchFilters.cshtml的部分视图中定义的文本框的代码,以及使用以下部分视图的视图2。

 @using (Html.BeginForm( "Validate","UploadEligibilityCodes",FormMethod.Post, new {id="UploadForm" , enctype = "multipart/form-data" }))
   {
 <div class="col-sm-1 form-group">
                            <button type="submit" class="SIMPLDocumentUploadSave" id="importbtn" value="Import" style="width: 100px">&nbsp;Import</button>
                        </div>
}

 <div class="col-sm-12 form-group SIMPLAdvancedFilterOptions">
                               @Html.Partial("SearchFilters")
                        </div>

I saw some examples using Sys.WebForms.PageRequestManager in ASP.Net, but the same i am not able to apply it html of mvc application.Please help :) 我看到了一些在ASP.Net中使用Sys.WebForms.PageRequestManager的示例,但同样,我无法将其应用于mvc应用程序的html。请帮助:)

Can you replace your submit button with regular one and call submit() on form manually with jQuery? 您可以用常规按钮替换您的Submit按钮,然后使用jQuery手动调用表单上的commit submit()吗? This can help you with postback issue 这可以帮助您解决回发问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM