使用ajax更新kendo网格时出现内部服务器错误

时间:2013-08-23 06:46:39

标签: ajax json asp.net-mvc-3 rss kendo-ui

我试图用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>

1 个答案:

答案 0 :(得分:1)

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

引起的
return Json(feedler, JsonRequestBehavior.AllowGet);

而不是;

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