Sarthak Sanghavi Sarthak Sanghavi - 1 month ago 20
AngularJS Question

are you missing a cast?


Cannot implicitly convert type 'DoctorFront.Models.DocMaster' to 'System.Collections.IEnumerable'. An explicit conversion exists (are you missing a cast?)


namespace DoctorFront.Controllers
{
public class DoctorController : ApiController
{
static readonly IDocRepositories Repository =new DocRepositories();
public IEnumerable GetAllDoctor()
{
return Repository.GetAll();
}

public IEnumerable GetDoctor(int id)
{

return Repository.Get(id);
}

}
}


Any help is appreciated.

Answer
public IEnumerable GetDoctor(int id) 
{

    return Repository.Get(id); // problem here
}

Your method GetDoctor is supposed to return an object of type IEnumerable. Your return statement is only returning a single DocMaster object.

So this should work:

public DocMaster GetDoctor(int id) 
{

    return Repository.Get(id);
}

Hopefully this helps!