コード例 #1
0
        // GET: Owner
        public ActionResult Index()
        {
            var test = Request.Cookies["OwnerId"];

            try
            {
                ViewBag.OwnerId = test.Value;
            }
            catch (Exception)
            {
                return(RedirectToAction("Index", "Home"));

                throw;
            }
            List <SelectListItem> list = new List <SelectListItem>();

            using (connection)
            {
                SqlCommand cmd = new SqlCommand("dbo.GetCategories", connection);
                cmd.CommandType = System.Data.CommandType.StoredProcedure;

                connection.Open();
                rdr = cmd.ExecuteReader();

                while (rdr.Read())
                {
                    list.Add(new SelectListItem
                    {
                        Text  = (string)rdr["Category"],
                        Value = rdr["Id"].ToString()
                    });
                }
                connection.Close();
            }

            ViewBag.Categories = list;

            return(View(repo.GetByOwnerID(test.Value)));
        }