Force lowercase property names from Json() in ASP.NET MVC

前端 未结 5 1101
孤独总比滥情好
孤独总比滥情好 2020-11-29 18:43

Given the following class,

public class Result
{      
    public bool Success { get; set; }

    public string Message { get; set; }
}

I a

5条回答
  •  温柔的废话
    2020-11-29 19:27

    Though it is an old question, hope below code snippet will be helpful to others,

    I did below with MVC5 Web API.

    public JsonResult Post(Request request)
        {
            var response = new Response();
    
            //YOUR LOGIC IN THE METHOD
            //.......
            //.......
    
            return Json(response, new JsonSerializerSettings() { ContractResolver = new CamelCasePropertyNamesContractResolver() });
        }
    

提交回复
热议问题