Online Training for Asp.net MVC Web Designing Development, MS SQL, Digital Marketing

Put Method Example in Asp.net Web API

Put is update method, is almost like Post , the only difference is that this method has Id parameter, for which the data to be updated in database
public HttpResponseMessage Put(int id, [FromBody]ClientModel client)
{
try
{
Client c = new Client();
c.CompanyName = client.CompanyName;
c.ContactPerson = client.ContactPerson;
c.Email = client.Email;
c.Phone = client.Phone;

// update client in database for this clientId
c.ClientId = id;

var returnMessage = Request.CreateResponse(HttpStatusCode.Created, c);
returnMessage.Headers.Location = new Uri(Request.RequestUri + "/" + c.ClientId.ToString());
return returnMessage;
}
catch (Exception ex)
{
return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex);
}
}
Comment
Name Email Website
Subscribe
 
Asp.Net Web API Put Example


Group Training