Skip to content
This repository has been archived by the owner. It is now read-only.
master
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.mdown

Mvc.Jsonp

Mvc.Jsonp is a simple ActionResult and Controller base class for adding JSONP support to MVC 3.

End of life

This repository has been archived and is now read-only.

Example

Just subclass your controller with JsonpControllerBase, like this:

public class HomeController : JsonpControllerBase
{
    public JsonpResult Index(string callback = "processStarships")
    {
        var starships = new List<Starship>
        {
            new Starship { Name = "Enterprise", Registry = "NCC-1701" },
            new Starship { Name = "Galaxy", Registry = "NCC-70637" },
            new Starship { Name = "Tikopai", Registry = "NCC-1800" }
        };

        return this.Jsonp(starships, callback, JsonRequestBehavior.AllowGet);
    }
}

If you don't want to make your controller a subclass of JsonpControllerBase, you can just return a JsonpResult, like this:

public class HomeController
{
    public JsonpResult Index(string callback = "processStarships")
    {
        var starships = new List<Starship>
        {
            new Starship { Name = "Enterprise", Registry = "NCC-1701" },
            new Starship { Name = "Galaxy", Registry = "NCC-70637" },
            new Starship { Name = "Tikopai", Registry = "NCC-1800" }
        };

        return new JsonpResult
        {
            Callback = callback,
            Data = starships,
            JsonRequestBehavior = JsonRequestBehavior.AllowGet
        };
    }
}

This will give you output of type application/javascript like this:

processStarships([{"Name":"Enterprise","Registry":"NCC-1701"},{"Name":"Galaxy","Registry":"NCC-70637},{"Name":"Tikopai","Registry":"NCC-1800"}]);

Building

To build with .NET 4.0, just run the included build.cmd. This will place Mvc.Jsonp.dll and its symbols in the output directory.

NuGet Package

To install Mvc.Jsonp from the NuGet repository, use this command:

PM> Install-Package Mvc.Jsonp

Acknowledgements

Mvc.Jsonp is based on http://stackoverflow.com/questions/758879/asp-net-mvc-returning-jsonp.

About

A simple ActionResult and Controller superclass for adding JSONP support to MVC 3.

Resources

License

Releases

No releases published

Packages

No packages published