Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You should not put any scripts in partials. Scripts belong to separate javascript files. They should not be mixed with markup. So put your script into a separate function:</p> <pre><code>function hookupAutoComplete() { // notice that since we have externalized this into a separate js file // we can no longer use url helpers here =&gt; we will fetch the url // from the textbox var url = $('#Name').data('url'); $('#Name').autocomplete({ source: function(request, response) { $.ajax({ url: url, data: JSON.stringify({ countryName: request.term }), dataType: "json", type: "POST", contentType: "application/json; charset=utf-8", dataFilter: function(data) { return data; }, success: function(data) { response($.map(data.d, function(item) { return { value: item.Country } })) }, error: function(XMLHttpRequest, textStatus, errorThrown) { alert(textStatus); } }); }, minLength: 2, focus: function( event, ui ) { $( '#Name' ).val( ui.item.Country ); return false; } }); } </code></pre> <p>which assumes that the url is stored as a HTML5 data-* attribute:</p> <pre><code>@Html.TextBoxFor(model =&gt; model.Name, new { data_url = Url.Action("GetCountriesB", "Country") }) </code></pre> <p>and then in the success callback of your AJAX request, once you load the partial into the DOM call this function:</p> <pre><code>$.ajax({ url: '/someurl', success: function(result) { $('#dialog').html(result); hookupAutoComplete(); } }); </code></pre> <p>Actually you might try removing the <code>$(document).ready(...)</code> from the script and it might actually work, but my recommendation is to externalize this script from your markup.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload