2014-04-03 4 views
0

안녕하세요 간단한 MVC 자동 완성, 내가 테스트 한 코드 및 "빈"mvc 프로젝트를 만들 때 작동하지만 intenet 응용 프로그램에서 정확한 코드를 수행 할 때 작동하지 않습니다 , 그것은 결코 자동 완성 메서드를 얻을 수 없습니다. 어떤 아이디어? 그래서 유선. 감사합니다ASP.NET MVC 4 자동 완성 작동하지 않습니다.

홈 컨트롤러

static List<Students> _students = new List<Students>() { 
     new Students{id=1,Name="Bob", Grade="B"}, 
     new Students{id=2,Name="Billy", Grade="A"}, 
     new Students{id=3,Name="Mike", Grade="B"} 
    }; 

    public ActionResult AutoMethod(string term) 
    { 
     //.... 
    } 


    public ActionResult Index() 
    { 
     return View(_students); 
    } 

인덱스보기

@model IEnumerable<MvcApplication1.Models.Students> 

    <script src="~/Scripts/jquery-1.10.2.js"></script> 
<script src="~/Scripts/jquery-ui-1.10.4.custom.min.js"></script> 
<link href="~/Content/jquery-ui-1.10.4.custom.min.css" rel="stylesheet" /> 


<script type="text/javascript"> 
    $(function() { 
    $("#searchText").autocomplete({ 
     source: '@Url.Action("AutoMethod")' 
    }); 

}); 

@using (Html.BeginForm()){ 
    @Html.TextBox("searchText"); 
    <input type="submit" value="submit" /> 
} 
<table> 
    <tr> 
     <th> 
      @Html.DisplayNameFor(model => model.Name) 
     </th> 
     <th> 
      @Html.DisplayNameFor(model => model.Grade) 
     </th> 

    </tr> 

    @foreach (var item in Model) 
    { 
     <tr> 
      <td> 
       @Html.DisplayFor(modelItem => item.Name) 
      </td> 
      <td> 
       @Html.DisplayFor(modelItem => item.Grade) 
      </td> 
     </tr> 
    } 

+0

: Scripts.Render ("~/번들 @/jquery ") 레이아웃 파일에서 작동합니다. "jquery 번들"에 두 개의 js 파일을 추가하면 작동하지 않습니다. 누군가가 그것을 모두 고치는 방법을 설명 할 수 있습니까? 왜 이러는거야? – Ben

답변

1

, 브라우저에서 결과 HTML 코드에서 봐 주시기 바랍니다, 확률값을 JavaScript 파일을 두 번 이상 참조하고 있습니다. 보기에서 일반적으로 사용되는 JavaScript 파일을 참조하는 것은 권장되지 않습니다. 대신 _SiteLayour.cshtml 또는 MVC의 "Bundling and minification"기능을 사용하십시오.

0

당신의 자동 완성 코드의 상단에 다음을 추가

<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/themes/excite-bike/jquery-ui.css" type="text/css" /> 
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script> 
<script src='http://code.jquery.com/ui/1.10.3/jquery-ui.js'></script> 

그리고 당신의 기능에 jQuery.noConflict();를 추가

$(function() { 
    jQuery.noConflict(); 
    $("#searchText").autocomplete({ 
     source: '@Url.Action("AutoMethod")' 
    }); 
내가 선을 제거하면 내가 발견
관련 문제