0

目前,我已经编写了以下 json 搜索方法。

[HttpPost]
    public JsonResult Search(string videoTitle)
    {
        var auth = new Authentication() { Email = "abc@smu.abc", 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 来设置标签样式,以便在项目从搜索输入中下拉时看起来更美观。

谢谢

4

1 回答 1

0

如果要返回纯 HTML,则不应返回 JSON,而应使用 ContentResult:

[HttpPost]
public ContentResult Search(string videoTitle)
{
    var auth = new Authentication() { Email = "smu@smu.com", 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 中。

于 2012-03-20T12:25:55.073 回答