Created
February 15, 2011 19:24
-
-
Save danlash/828060 to your computer and use it in GitHub Desktop.
A proposal to allow JsonResult from GET in ASP.NET MVC except for arrays
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var model = new {AccountNumber = 123}; | |
var arr = new[] { model }; | |
Console.WriteLine(CurrentJson(model)); | |
Console.WriteLine(CurrentJson(arr)); | |
Console.WriteLine(CurrentJson(arr,true)); | |
Console.WriteLine(SafeJson(model)); | |
Console.WriteLine(SafeJson(arr)); | |
Console.ReadKey(); | |
} | |
static string CurrentJson(object model) | |
{ | |
return model is IEnumerable ? "get allowed" : "get not allowed"; | |
} | |
static string CurrentJson(object model, bool allowGet) | |
{ | |
return "manually allow get"; | |
} | |
static string SafeJson(object model) | |
{ | |
return "get allowed"; | |
} | |
static string SafeJson(IEnumerable model) | |
{ | |
return "get not allowed, force manual method"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment