Why is JsonRequestBehavior needed?

后端 未结 5 1269
[愿得一人]
[愿得一人] 2020-11-22 05:27

Why is Json Request Behavior needed?

If I want to restrict the HttpGet requests to my action I can decorate the action with the [Http

5条回答
  •  天命终不由人
    2020-11-22 06:03

    You do not need it.

    If your action has the HttpPost attribute, then you do not need to bother with setting the JsonRequestBehavior and use the overload without it. There is an overload for each method without the JsonRequestBehavior enum. Here they are:

    Without JsonRequestBehavior

    protected internal JsonResult Json(object data);
    protected internal JsonResult Json(object data, string contentType);
    protected internal virtual JsonResult Json(object data, string contentType, Encoding contentEncoding);
    

    With JsonRequestBehavior

    protected internal JsonResult Json(object data, JsonRequestBehavior behavior);
    protected internal JsonResult Json(object data, string contentType, 
                                       JsonRequestBehavior behavior);
    protected internal virtual JsonResult Json(object data, string contentType, 
        Encoding contentEncoding, JsonRequestBehavior behavior);
    

提交回复
热议问题