Click here to Skip to main content
15,887,295 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
 public class CountriesController : ApiController
    {

<pre>     private MyDB db = new MyDB();

        public List<SelectListItem> GetDropDownList<T>(
                 string text, string value, string selected) where T : class
        {
            List<SelectListItem> list = new List<SelectListItem>();
            list.Add(new SelectListItem { Text = "-Please select-", Value = string.Empty });
            IQueryable<T> result = db.Set<T>();
            var lisData = (from items in result
                           select items).AsEnumerable().Select(m => new SelectListItem
                           {
                               Text = (string)m.GetType().GetProperty(text).GetValue(m),
                               Value = (string)m.GetType().GetProperty(value).GetValue(m),
                               Selected = (selected != "") ? ((string)
                                 m.GetType().GetProperty(value).GetValue(m) ==
                                 selected ? true : false) : false,
                           }).ToList();
            list.AddRange(lisData);
            return list;
        }



}


How can i pass T(Entity) Value to WEB API 2 through below function

note : Web api and Website in seperate projects.


  public async Task<IEnumerable<TEntity>> GetAllProductAsync(string apiurl)
        {
string apiurl = "/Api/GetCountres/'01'/'01'/'01'"
            IEnumerable<TEntity> TEntity = null;
            HttpResponseMessage response = await client.GetAsync($"{apiurl}");
            if (response.IsSuccessStatusCode)
            {
                string stringData =  response.Content.ReadAsStringAsync().Result;
                 TEntity = JsonConvert.DeserializeObject<IEnumerable<TEntity>>(stringData);
            }
            return TEntity;
        }


What I have tried:

How can i pass T(Entity) Value to WEB API 2 through   below function 

note : Web api and Website in separate projects.


need pass Entity class to WEB API 2 from API URL?
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900