2014-09-01 3 views
1

이 코드는 하나의 열에서 자동 완성 만 반환하며, 두 개의 열에서 자동 완성을 가져옵니다. 나는 그 문제가 무엇인지 알고 싶다. 제발, 만약 아무도 대답을 알고 나를 도와주세요.
감사합니다.둘 이상의 열에서 자동 완성을 표시하는 방법은 무엇입니까?

public JsonResult SearchFromTable(string name) 
    {    
     AccountingDataLayer.AccountingSMSEntities context = new AccountingDataLayer.AccountingSMSEntities(); 
     var search = (from s in context.Products 
          where s.Name == name || s.FullCode == name 
          select new{s.FullCode , s.Name , s.Description }); 

     return Json(search, JsonRequestBehavior.AllowGet); 
    } 

    public JsonResult AutoCompleteProductName(string term , string t) 
    { 
     AccountingDataLayer.AccountingSMSEntities context = new AccountingDataLayer.AccountingSMSEntities(); 
     var result = (from p in context.Products 
         where p.Name.ToLower().Contains(term.ToLower()) || p.FullCode.ToLower().Contains(t.ToLower()) 
         select new { p.Name , p.FullCode }).Distinct(); 
     return Json(result, JsonRequestBehavior.AllowGet); 
    } 

    $("#search").autocomplete({ 
     source: function (request, response) { 
      $.ajax({ 
       url: "/InVoiceStock/AutoCompleteProductName", 
       type: "POST", 
       dataType: "json", 
       data: { term: request.term , t: request.t }, 
       success: function (data) { 
        response($.map(data, function (item , t) { 
         return { label: item.Name, value: item.Name, label: t.FullCode, value: t.FullCode }; 
        })) 
       } 
      }) 
     }, 
     messages: { 
      noResults: "", results: "" 
     } 
    });     
});` 
+0

Microsoft Visual Studio를 사용하고 있습니까? .net을 사용하고 있습니까? Winforms? WPF? – Cullub

답변

0

t 변수를 불필요하게 만들었습니다. 요청 개체에는 현재 텍스트 입력에있는 값을 참조하는 하나의 term 속성 만 있습니다. 그래서 request.t

data: { term: request.term , t: request.t } 

가 null이됩니다 액션 메소드 string t에서, 더 나아가 여기에 정의되지 않습니다과의 where 절을 사용 term에,

var result = (from p in context.Products 
    where p.Name.ToLower().Contains(term.ToLower()) || p.FullCode.ToLower().Contains(t.ToLower()) 
    select new { p.Name , p.FullCode }).Distinct(); 

이 문제를 해결하려면 필터링에 사용되지 않습니다 두 조건 모두 불필요한 참조를 제거하십시오. t

관련 문제