In the previous article, we saw about how to get the data from Web-API, using jQuery AJAX.
Here, we are going to see, how to pass the input value to the Service method parameter, using jQuery AJAX.
Step 1
Step 1
Write Web-API Services in another project
Here, just write the Service to get the company details, which is based on company Id. This company Id is input just from jQuery AJAX parameter.
Here, just write the Service to get the company details, which is based on company Id. This company Id is input just from jQuery AJAX parameter.
- using System.Collections.Generic;
- using System.Net;
- using System.Net.Http;
- using System.Web.Http;
- using System.Web.Http.Description;
- using TS_EF_API.Repository;
- namespace TS_EF_API.Controllers {
- /// <summary>
- /// Company
- /// </summary>
- public class CompanyController: ApiController {#
- region Global Declaration
- private IRepository < Company > _Companyrepository = null;
- /// <summary>
- /// Constructor for Company Controller
- /// </summary>
- public CompanyController() {
- this._Companyrepository = new Repository < Company > ();
- }#endregion
- /// <summary>
- /// Get Company Detail
- /// </summary>
- /// <remarks>
- /// Get Company Details
- /// </remarks>
- /// <param name="CompanyId"></param>
- /// <returns code="200"></returns>
- [ResponseType(typeof(Company))]
- [Route("api/GetCompany")]-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - > It will call by Jquery ajax[HttpGet]
- public HttpResponseMessage GetCompany(int CompanyId) -- -- -- -- > This companyid is the incoming parameter and the input get from jquery ajax(In Step 2: refer 7 th line it 's shows how to pass input parameter to service method. {
- var result = _Companyrepository.GetById(CompanyId);
- HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK, result);
- return response;
- }#endregion

Hadshana KamalanathanPosted Jul 22, 2018, 1:08 AM
Nice one..
Humayun Kabir MamunPosted Feb 28, 2017, 6:12 AM
Thanks for this nice article...