Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/asp.net-mvc-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
带有JsonFilterAttribute的MVC3不';我不再工作了_Json_Asp.net Mvc 3_Filter - Fatal编程技术网

带有JsonFilterAttribute的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

在我转到MVC3之前,这段代码运行得很好

        [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。有更新的参考资料吗?也许这个: