带有JsonFilterAttribute的MVC3不';我不再工作了
在我转到MVC3之前,这段代码运行得很好带有JsonFilterAttribute的MVC3不';我不再工作了,json,asp.net-mvc-3,filter,Json,Asp.net Mvc 3,Filter,在我转到MVC3之前,这段代码运行得很好 [HttpPost] [ActionName("GetCommentListForServiceCall")] [UrlRoute(Path = "mobile/servicecalls/{id}/comments", Order=1)] [UrlRouteParameterConstraint(Name = "id", Regex = @"\d+")] [OutputCache(CacheProfile
[HttpPost]
[ActionName("GetCommentListForServiceCall")]
[UrlRoute(Path = "mobile/servicecalls/{id}/comments", Order=1)]
[UrlRouteParameterConstraint(Name = "id", Regex = @"\d+")]
[OutputCache(CacheProfile = "MobileCacheProfile")]
[JsonFilter(JsonDataType = typeof(ServiceCallCommentNewDTO), Param = "comment")]
public JsonNetResult CreateCommentForServiceCall(int id, ServiceCallCommentNewDTO comment)
{
ServiceCallComment entity = coreSvc.SaveServiceCallComment(id, 0, comment.CategoryId, comment.Comment);
SetResponseCode(HttpStatusCode.Created);
SetContentLocation(string.Format("mobile/servicecalls/{0}/comments/{1}", id.ToString(), entity.Id.ToString()));
return new JsonNetResult(entity); ;
}
以下是JSonFilterAttribute代码
public class JsonFilterAttribute : ActionFilterAttribute
{
public string Param { get; set; }
public Type JsonDataType { get; set; }
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
if (filterContext.HttpContext.Request.ContentType.Contains("application/json"))
{
string inputContent;
using (var sr = new StreamReader(filterContext.HttpContext.Request.InputStream))
{
inputContent = sr.ReadToEnd();
}
var result = JsonConvert.DeserializeObject(inputContent, JsonDataType, new JsonSerializerSettings{TypeNameHandling = TypeNameHandling.All});
filterContext.ActionParameters[Param] = result;
}
}
}
现在JsonFilter不再获取对象。它总是返回空值吗
在MVC3中有什么我必须做的吗?您不再像ASP.NET MVC 3那样需要此属性。我试图对该属性进行注释,但始终得到一个空对象。我必须在其他地方包括一些东西吗?链接是404。有更新的参考资料吗?也许这个: