2012-03-20 41 views
0

當前,我已經編寫了以下json搜索方法。使用HTML包含對象屬性並返回JSON

[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

如果你想返回純HTML你不應該返回JSON,你倒是應該使用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。