public ActionResult myview()
{
IEnumerable<MyempModel> empobj = null;
HttpClient hc = new HttpClient();
hc.BaseAddress = new Uri("http://localhost:2034/api/");
var apicontroller = hc.GetAsync("values");
apicontroller.Wait();
var resultdisp = apicontroller.Result;
if (resultdisp.IsSuccessStatusCode)
{
var reademptable = resultdisp.Content.ReadAsAsync<List<MyempModel>>();
reademptable.Wait();
empobj = reademptable.Result;
}
return View(empobj);
}
MyempModel should same as entity data model field ............
public class MyempModel
{
public int sno { get; set; }
public string name { get; set; }
public string ftnsme { get; set; }
}
if your controller return data in xml format .........then use two line code in app start folder in WebApiConfig file
// Web API configuration and services
config.Formatters.Clear();
config.Formatters.Add(new JsonMediaTypeFormatter());
No comments:
Post a Comment