【发布时间】:2015-02-01 17:33:28
【问题描述】:
我使用 jQuery Ajax 和 ASP.Net MVC 创建了一个级联下拉菜单 我已经设置了我的 ajax 请求 OnChange of dropdown 这是我的代码:
@Html.DropDownList("Agency_Id", null, htmlAttributes: new { @class = "form-control", @onchange = "bring_projects(this.value,'bring_projects_by_agency','Project_Id')" })
项目下拉:
@Html.DropDownList("Project_Id", null, htmlAttributes: new { @class="form-control"})
这是我的脚本:
function bring_projects(id, funcs, divname) {
var ajax_image = "<img src='./Content/loading.GIF' >";
$('#' + divname).html(ajax_image);
var params = "&agency_id=" + id;
$.ajax({
url: funcs,
type: "POST",
data: params,
})
.done(function (r) {
$('#' + divname).html(r);
});
}
它给出了以下错误:
Server Error in '/' Application.
The required anti-forgery form field "__RequestVerificationToken" is not present.
注意: 我没有提交表单,我只是在我的编辑页面中执行 ajax 请求 OnChange of DropDown。
【问题讨论】:
-
如果您查看页面生成的 HTML 源代码,您会看到自动生成的表单中有一个隐藏的输入。您需要将其包含在您的 AJAX 请求中,因为它用于确保请求实体是合法的。
标签: javascript jquery asp.net ajax asp.net-mvc