my code stock.com

Vishrut Jambudi

Pass object to Web Api from MVC Controller
by Vishrut Jambudi

Pass object to Web Api from MVC Controller

Snippet options

Download: Download snippet as pass-object-to-web-api-from-mvc-controller.cpp.
Copy snippet: For this you need a free my code stock.com account.
Embed code : You will find the embed code for this snippet at the end of the page, if you want to embed it into a website or a blog!

using (var client = new HttpClient())
 2                     {
 3 
 4                         var myContent = JsonConvert.SerializeObject(ufo);
 5                         var buffer = System.Text.Encoding.UTF8.GetBytes(myContent);
 6                         var byteContent = new ByteArrayContent(buffer);
 7                         byteContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
 8                         var result = client.PostAsync("http://localhost:50148/api/Registration/Save", byteContent).Result;  
 9 
10 
11                         if (result.IsSuccessStatusCode)
12                         {
13                             string responseString = result.Content.ReadAsStringAsync().Result;
14                             return RedirectToAction("Index");
15                         }
16                     }

Create a free my code stock.com account now.

my code stok.com is a free service, which allows you to save and manage code snippes of any kind and programming language. We provide many advantages for your daily work with code-snippets, also for your teamwork. Give it a try!

Find out more and register now

You can customize the height of iFrame-Codes as needed! You can find more infos in our API Reference for iframe Embeds.