2012-10-05 5 views
0

MVC3 웹 프로젝트에서 ui jquery 자동 완성을 사용하고 js 파일을 외부 js 파일에 보관하고 웹 페이지에 포함 시켰지만 작동하지 않습니다. 사용자 @ Html.Raw가 ui jquery 자동 완성에서 작동하지 않습니다?

나는 UI를 JQuery와 자동 완성에 대한 JS 파일에 다음 코드를 사용 :

$(function() { 
    $("#ReportsTo_FullName").autocomplete({ 
     source: function (request, response) { 
      var linkPath = "@Html.Raw(Url.Action("AutocompleteSuggestions", "Employee", new { @term = "Term", @moduleName="ModuleName"}))"; 
      linkPath = linkPath.replace("Term", request.term); 
      linkPath = linkPath.replace("ModuleName", "Employee"); 

      $.post(linkPath, function (data) { 
       response($.map(data, function (item) { 
        return { label: item.FullName, value: item.Id } 
       } 
       )); 
      }) 
      $.error(function (xhr, ajaxOptions, thrownError) { alert(thrownError); }) 
     }, 
     minLength: 1, 
     focus: function (event, ui) { 
      $("#ReportsTo_FullName").val(ui.item.label); 
      return false; 
     }, 
     select: function (event, ui) { 
      if (ui.item) { 
       $("#ReportsTo_FullName").css('border', ''); 
       $("#ReportsTo_FullName").val(ui.item.label); 
       $("#ReportsToId").val(ui.item.value); 
       return false; 
      } 
     }, 
     change: function (event, ui) { 
      if (ui.item == null) { 
       $("#ReportsTo_FullName").css({ 'border': '1px solid #ff0000' }); 
       $("#ReportsToId").val(null); 
      } 
     } 
    }); 
}); 

그러나 실행하는 데 실패하고 표시되지 자동 완성됩니다.

위의 jquery가 잘못 되었나요?

이 문제를 해결하는 방법?

+1

이 문제를 해결하려면 먼저 약간의 연구를해야합니다. [this] (http://stackoverflow.com/q/7902213/944681), [this] (http://stackoverflow.com/q/4599169/944681) 또는 [this] (http : // www. .google.com) 우선 ... –

답변

2

이 사용할 수 없습니다 :이 서버 코드가

JS 파일에서
@Html.Raw(Url.Action("AutocompleteSuggestions", "Employee", new { @term = "Term", @moduleName="ModuleName"})) 

입니다. 페이지에 숨겨진 필드를 만든 다음에 만이 데이터를 가져올 수 있습니다.