2012-03-20 2 views
0

을 반환합니다. 다음 json 검색 방법을 작성했습니다.JSON에서 HTML로 개체 속성을 포함하고 현재

[HttpPost] 
    public JsonResult Search(string videoTitle) 
    { 
     var auth = new Authentication() { Email = "[email protected]", Password = "abc" }; 
     var videoList = server.Search(auth, videoTitle); 
     String html = ""; 
     foreach(var item in videoList){ 
      var video = (Video)item; 
      html += "<b>"+video.Title+"</b>"; 
     } 

     return Json(html, JsonRequestBehavior.AllowGet); 
    } 

화면에서이 값을 반환합니다.

"\u003cb\u003eAge of Conan\u003c/b\u003e" 

어떻게해야합니까? 내가 이것을하고 싶은 이유는 CSS를 사용하여 스타일 태그를 만들 수 있기 때문에 검색 입력에서 항목이 드롭 될 때 미적으로 더 잘 보입니다.

감사

답변

0

당신이 JSON을 반환하지 않아야 순수한 HTML을 반환 할 경우, 오히려 ContentResult 사용해야합니다

[HttpPost] 
public ContentResult Search(string videoTitle) 
{ 
    var auth = new Authentication() { Email = "[email protected]", Password = "test" }; 
    var videoList = server.Search(auth, videoTitle); 
    String html = ""; 

    foreach(var item in videoList) 
    { 
     var video = (Video)item; 
     html += "<b>"+video.Title+"</b>"; 
    } 

    return Content(html, "text/html"); 
} 

당신이를 요청할 수를 기준 jQuery.get()와 인서트 직접 DOM에.

관련 문제