Populate dropdown list based on data retrieved from database in MVC Application (Controller and BLL)

Controller

    public JsonResult FillRoles()
    {
      return Json(BLLFile.FillUserRoles(), JsonRequestBehavior.AllowGet);
    } 

Code in BLL file

 public static List<sp_FillUserRoles_Result> FillUserRoles()
        {
            using (Db_obj db = new Db_obj())
            {
                return db.sp_FillUserRoles().ToList();
            }
        }

Explanation

Now, Understand the sequence:

  1. View will ask controller to send data.
  2. FillRoles() Method in controller will request data from BLL file so it will give call to FillUserRoles method in BLL file.
  3. FillUserRoles() in BLL file will give call to the stored procedure in DB named sp_FillUserRoles(). This procedure will return the data and the data retrieved will be converted into a list. Note that the call to stored procedure is given using an object of DB in a very similar way we give normally to a method of other class.
  4. The data will be sent back to controller form here and it will send the data to the view.

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Blog at WordPress.com.

Up ↑

Design a site like this with WordPress.com
Get started