Here is my code :
calling web api from MVC controller
using(HttpClient client = new HttpClient())
{
client.BaseAddress = new Uri("http://localhost:61810/api/Grid/GetConfiguration");
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
HttpContent content = new StringContent(JsonConvert.SerializeObject(objControlConfig), Encoding.UTF8, "application/json");
HttpResponseMessage responseMessage = client.PostAsync(new Uri("http://localhost:61810/api/Grid/GetConfiguration"), content).Result;
var message = responseMessage.Content.ReadAsStringAsync().Result;
}
web api call:
-------------------
[HttpPost]
public JsonResult GetConfiguration([FromBody]ControlConfig objControlConfig)
{
string result = string.Empty;
try
{
using (SqlConnection con = new SqlConnection(strCon))
{
con.Open();
SqlCommand cmd = new SqlCommand("BWCC_SPGETCONFIG", con);
cmd.CommandType = System.Data.CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Category", objControlConfig.Category);
cmd.Parameters.AddWithValue("@SubCategory", objControlConfig.SubCategory);
result = Convert.ToString(cmd.ExecuteScalar());
con.Close();
}
}
catch (Exception e)
{
}
if (result != null)
return Json(result);
else
return null;
}
this "[FromBody]ControlConfig objControlConfig" is always getting null .........tried different ways but no luck.
could you plz help anyone.
Thanks!
Anitha.