Ju-chan
Ju-chan

Reputation: 508

Properly exposing C# methods to jQuery

I would like to ask a question.

Recently, I've learned how to make jQuery use C# methods via consuming from an ASP.NET Web service. I am thinking of exposing some database access methods such as retrieving a list of records from the database for rendering using a jQuery library.

I have on top of my head is that I create a separate project in my solution, which is a Web service project to be able to expose the said data access methods (located on a separate project also in the solution). The web service will act as interaction between my jQuery and my data access methods.

I am visualizing my idea like this:

What I envision...

My question is that, is my idea a good thing to do, and if not, how do you properly expose C# data access objects for use with jQuery?

Thanks!

EDIT: The Web UI is an ASP.NET Web Forms, specifically version 2.0. I'm doing this in preparation to my next job.

Upvotes: 1

Views: 186

Answers (2)

Shan Khan
Shan Khan

Reputation: 10329

As Richard has already explain i will extend it and suggest you to use AngularJs instead of simple of calling jquery ajax.

Why AngularJS?

HTML is great for declaring static documents, but it falters when we try to use it for declaring dynamic views in web-applications. AngularJS lets you extend HTML vocabulary for your application. The resulting environment is extraordinarily expressive, readable, and quick to develop.

Case Studies for example

Upvotes: 0

Richard Schneider
Richard Schneider

Reputation: 35477

Yes, this is the correct approach. Typically, the Web Service is a REST API (http://en.wikipedia.org/wiki/Representational_state_transfer) that returns JSON/JSONP. This allows the client (JQuery) to use AJAX, async calls to the server.

Web API 2 (http://www.asp.net/web-api/overview/getting-started-with-aspnet-web-api/tutorial-your-first-web-api) is an easy way to expose an REST API in c#.

Upvotes: 1

Related Questions