0

我试图用 ajax 更新网格,但我无法成功地在控制器和使用 ajax 的视图之间传递和获取值当我运行程序时,它的输出是这样的

[object Object]++error++内部服务器错误

所以我需要帮助

HomeController 功能

    [HttpGet]
    public ActionResult RssCek(string value)
    {
        XDocument rssXml = new XDocument();
        switch (value)
        {
            case "Ekonomi": 
                {
                    rssXml = XDocument.Load("http://sozcu.com.tr/rss.php");
                    break;
                }
            case "Siyaset":
                {
                     rssXml = XDocument.Load("http://www.milliyet.com.tr/D/rss/rss/Rss_4.xml");
                    break;
                }
            case "Yaşam":
                {
                     rssXml = XDocument.Load("http://www.milliyet.com.tr/D/rss/rss/Rss_5.xml");
                    break;
                }
             default:
                {
                    rssXml = XDocument.Load("http://sozcu.com.tr/rss.php");
                }
                break;
        }


        var feedler = from feed in rssXml.Descendants("item")
                      select new Rss
                      {

                          Baslik = feed.Element("title").Value,
                          Link = "<a href=\"" + feed.Element("link").Value + "\">Oku</a>",
                          Aciklama = feed.Element("description").Value
                      };

        var valueToReturn = new JsonResult { Data = feedler };
        return valueToReturn;


    }

IndexView 网格代码

@Html.Kendo().Grid(Model)    
    .Name("Grid").Pageable()
    .Columns(columns =>
    {
        columns.Bound(p => p.Baslik).Groupable(false);
        columns.Bound(p => p.Aciklama).Encoded(false);
        columns.Bound(p => p.Link).Encoded(false);

    })
    .DataSource(dataSource => dataSource
        .Ajax()
        .Read(read => read.Action("RssCek", "Home"))
    )

IndexView JavaScript 代码

<script>
    function select(e) {
        var value = $(e.item).find("> .k-link").text();


            $.ajax({
                url: '@Url.Action("RssCek", "Home")',
                type: 'GET',
                contentType: 'application/json; charset=utf-8',
                data: { value: value},
                success: function (feedler)
                {
                    document.write(feedler);
                },
                error: function (request, status, error)
                {document.write(request+"++"+ status+"++"+ error);}
                });
    }
</script>
4

1 回答 1

1

我发现问题是由于缺少 JsonRequestBehavior.AllowGet

return Json(feedler, JsonRequestBehavior.AllowGet);

代替 ;

var valueToReturn = new JsonResult { Data = feedler };
        return valueToReturn;
于 2013-08-23T07:17:04.297 回答