简体   繁体   中英

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.

$("#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.

 @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 :)

Can you replace your submit button with regular one and call submit() on form manually with jQuery? This can help you with postback issue

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.

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