内的动作参数值我有我从jQuery的发布到一个动作:获得一个动作过滤器
[HttpPost]
public void UpdateGroupName(int groupId, string name)
{
authorisationRepository.UpdateGroupName(groupId, name);
}
也能正常工作与groupId
和name
。我还有其他一些小组操作,因此我想使用授权属性来确保执行更改的人员有权进行更改。
我已经有一个AuthorizationAttribute
,通过访问filterContext.HttpContext.Request.Params["groupId"]
在GET请求上成功检索groupId
,但是当谈到POST时,它不起作用。 Request.Form
是空的,Request.Params
也是空的。
下面是我在我的授权属性代码:
public int groupId { get; set; }
protected override bool AuthorizeCore(HttpContextBase httpContext)
{
username = httpContext.User.Identity.Name.Split('\\').Last();
// awesome permissions checking goes here...
return authorized;
}
public override void OnAuthorization(AuthorizationContext filterContext)
{
groupId = int.Parse(filterContext.HttpContext.Request.Params["groupId"]); // this line throws an exception
base.OnAuthorization(filterContext);
}
我已经看过这个answer但我Form
属性为空:(
更新,以显示jQuery的岗位:
var serverComm = {
post: function (url, data) {
return $.ajax({
url: url,
type: 'POST',
contentType: 'application/json; charset=utf-8',
data: JSON.stringify(data)
});
},
get: function (url, data) {
return $.ajax({
url: url,
type: 'GET',
cache: false,
contentType: 'application/json; charset=utf-8',
data: data
});
}
};
// some awesome code later...
serverComm.post(editGroupNameUrl, { groupId: group.id, name: newName })
而参数是Form参数吗?有没有机会在QueryString上? – ivowiblo 2012-03-01 15:28:31
QueryString为空。你是什么意思“是形式参数”?您可以在顶部代码示例 – soniiic 2012-03-01 15:32:07
中看到我的操作,您可以发布表单代码吗? – ivowiblo 2012-03-01 15:34:14