I know MVC controllers are quite good at serving JSON formatted AJAX requests, but is there any built-in ASP.NET functionality I can use for these type calls from a plain old web forms site?
相关问题
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Carriage Return (ASCII chr 13) is missing from tex
- Using :remote => true with hover event
If you've got .NET 3.5 installed on the server, you can take advantage of the JSON serialization tools that ship with the framework.
This uses the DataContractJsonserializer class.
Use generic web handler. i.e. ashx. These are even faster than MVC actions.
Web API works fine with Web Forms. http://www.asp.net/web-api/overview/creating-web-apis/using-web-api-with-aspnet-web-forms
My preferred method in this scenario is using a generic web handler (.ashx) and JSON.net http://james.newtonking.com/json
It's simple, fast and lightweight.
A simple example would be:
You could use built-in ASP.NET AJAX.
Option 1 - use a web service (if you want the functionality to be reusable):
Option 2 - use page methods (if you want the functionality on a single page without creating a web service):
In either case JSON will be used for data transfer.
Here is an extensive tutorial with some code samples.
However, ASP.NET AJAX is often blamed for inefficiency - for instance, JS it generates tends to be rather large. So, if you are concerned with performance, you'd want to test it thoroughly.
You might also have a look at this thread: .NET AJAX Calls to ASMX or ASPX or ASHX?