ASP.NET MVC: How to create an action filter to output JSON?

后端 未结 3 1834
抹茶落季
抹茶落季 2021-01-03 08:03

My second day with ASP.NET MVC and my first request for code on SO (yep, taking a short cut).

I am looking for a way to create a filter that intercepts the current o

3条回答
  •  余生分开走
    2021-01-03 08:22

    You haven't mentioned only returning the JSON conditionally, so if you want the action to return JSON every time, why not use:

    public JsonResult Index()
    {
        var model = new{ foo = "bar" };
        return Json(model);
    }
    

提交回复
热议问题