Click here to Skip to main content
15,890,690 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
public ActionResult Details(int id)
        {
            adminContext AdminContext = new adminContext();
            admin user =AdminContext.userAdmin.Single(xyz => xyz.recid == id);
            return View(user);
        }



context

C#
public class adminContext :DbContext
    {
        public DbSet<admin> userAdmin { get; set; }
    }


What I have tried:

i created a context class and calling that context class in web config file then am calling those data through controller the above code please help me to find a solution
Posted
Updated 22-Sep-16 19:43pm

1 solution

use SingeOrDefault[^]

C#
admin user = AdminContext.userAdmin.SingleOrDefault(xyz => xyz.recid == id);
           if(user !=null)
           {
               // your code to process
           }
           else
           {
               // show validation message, for item not present
           }
 
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