无法加载资源:服务器响应状态为500

时间:2014-09-17 12:18:49

标签: jquery ajax asp.net-mvc-4 orchardcms orchardcms-1.7

我在控制台中看到一些错误

“无法加载资源:服务器响应状态为500(内部服务器错误)http://Orchard.Club/Member/List

当我尝试复制此链接并运行它时。它说“所需的防伪表格字段”__RequestVerificationToken“不存在。”

控制列表视图

@{            
Script.Require("jQuery");
Script.Require("jQueryUI");
Script.Require("flexigrid");

Style.Include("Common.css");
Style.Include("flexigrid.css");
Style.Include("flexigrid.pack.css");
}



@using (Html.BeginForm())
{

@Html.AntiForgeryTokenOrchard()

<table id="jobListing" style="display: none"></table>

}


@using (Script.Foot())
{     
<script type="text/javascript">        
    $(document).ready(function () {
        $('#jobListing').flexigrid({
            url: '@Url.Action("List", "Member")',
            formData: {
                __RequestVerificationToken: '@Html.AntiForgeryTokenValueOrchard()'
            },
            dataType: 'json',
            colModel: [
                {
                    display: 'Caption',
                    name: 'Caption',
                    width: 180,
                    sortable: true,
                    align: 'left'
                }, {
                    display: 'Name',
                    name: 'Name',
                    width: 180,
                    sortable: true,
                    align: 'left'
                }, ]
        });
    });        

</script>

}

控制器

         public ActionResult ControlList()
    {
        return View();
    }

    [ValidateAntiForgeryToken]
    public ActionResult List()
    {            
        List<Controls> controls = new List<Controls>();

        controls.Add(new Controls() { Id = 1, Caption = "1", Name = "2", ControlType = "textbox" });
        controls.Add(new Controls() { Id = 2, Caption = "1", Name = "2", ControlType = "textbox" });
        controls.Add(new Controls() { Id = 3, Caption = "1", Name = "2", ControlType = "textbox" });

        return CreateFlexiJson(controls.ToList(), 1,1);            
    }

    private JsonResult CreateFlexiJson(IEnumerable<Controls> items, int page, int total)
    {
        return Json(
                new
                {
                    page,
                    total,
                    rows =
                        items
                        .Select(x =>
                            new
                            {
                                id = x.Id,
                                // either use GetPropertyList(x) method to get all columns 
                                cell = new object[] { x.Caption, x.Name, x.ControlType, x.Id }
                            })
                }, JsonRequestBehavior.AllowGet);
    }

0 个答案:

没有答案