Click here to Skip to main content
15,921,028 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,
i need help, i have written a service which is fetching records from database table. its return type is List<> and i am calling the service in a controller method.
but it is giving me casting error. My code is below:
this is the service :

XML
public List<tblClaimRegistration> GetAllClaimRegistrationRecords()
      {
          MACPEntities entities;
          entities = new MACPEntities();

          IEnumerable<tblClaimRegistration> records = from obj in entities.tblClaimRegistrations
                                                      select obj;
          return records.ToList();


      }



this is the controller method:

XML
[HttpPost]
    public ActionResult ToControl()
    {
        ServiceReference1.Service1Client svc = new ServiceReference1.Service1Client();
        List<tblClaimRegistration> ClaimRegistartion= (List<tblClaimRegistration>)svc.GetAllClaimRegistrationRecords().ToList();
 ViewData["ClaimRegistartion"] = ClaimRegistartion;

        return View("TestView");
      
    }


the above code is giving error as
Cannot convert type 'System.Collections.Generic.List to 'System.Collections.Generic.List<MACP.Models.tblClaimRegistration>'	C:\inube\MACPCMSIntegration\MACP\Controllers\HomeController.cs	127	60	MACP


pls some body help what should i do.
Posted

The method "GetAllClaimRegistrationRecords()" already return a "List<tblclaimregistration>" type.

So you doesn't need to ask for ToList()...

Just do it :
List<tblClaimRegistration> ClaimRegistartion= svc.GetAllClaimRegistrationRecords()
 
Share this answer
 
Comments
Saumya J Pandey 4-Oct-11 6:38am    
no it is still giving error. not working.
i got the solution :

[HttpPost]
    public ActionResult ToControl()
    {
        ServiceReference1.Service1Client svc = new ServiceReference1.Service1Client();
       
 ViewData["ClaimRegistartion"] = svc.GetAllClaimRegistrationRecords();
 
        return View("TestView");
      
    }


it will work.
 
Share this answer
 

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