title: jQuery Autocomplete not working inside ASP.NET MVC View Dynamically Loaded
body: <p>I'm loading an ASP.NET MVC 3 View dynamically. Inside a view, there is a Textbox that needs to have "automcomplete". Code below:</p>
  
  <pre><code>@model CountryViewModel
  
  @using (Html.BeginForm("Create", "Country", FormMethod.Post)) {
  @Html.ValidationSummary(true)
  &lt;div class="field"&gt;
  @Html.LabelFor(model =&gt; model.Name)
  @Html.TextBoxFor(model =&gt; model.Name)
  @Html.ValidationMessageFor(model =&gt; model.Name)
  &lt;/div&gt;
  
  &lt;div class="field"&gt;
  @Html.LabelFor(model =&gt; model.Description)
  @Html.TextBoxFor(model =&gt; model.Description)
  &lt;/div&gt;
  
  &lt;div class="field"&gt;
      @Html.LabelFor(model =&gt; model.Latitude)
      @Html.TextBoxFor(model =&gt; model.Latitude)
  &lt;/div&gt;
  
  &lt;div class="field"&gt;
      @Html.LabelFor(model =&gt; model.Longitude)
      @Html.TextBoxFor(model =&gt; model.Longitude)
  &lt;/div&gt;
  
  @Html.HiddenFor(model =&gt; model.CultureId, new { id = "CultureId" })
  }
  
  &lt;script type="text/javascript"&gt;
  
  $(document).ready(function () {
      $('#Name').autocomplete({
          source: function(request, response) {
              $.ajax({
                  url: '@(Url.Action("GetCountriesB", "Country"))',
                  data: "{ '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></p>
  
  <p>I am loading this View inside a jQuery UI Dialog. When I debug using Firebug, the "script" tag seems not be loaded, hence autocomplete is not working.</p>
  
  <p>Any idea why this behavior?</p>
  
  <p>Thanks</p>