Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. Use A Cookie To Send PersonID To Different Page

Use A Cookie To Send PersonID To Different Page

Scheduled Pinned Locked Moved .NET (Core and Framework)
databasehelpquestion
1 Posts 1 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • X Offline
    X Offline
    xnaLearner
    wrote on last edited by
    #1

    Hey guys so atm when the user goes to the holiday page, they can do 1 of 2 things 1)use a drop down box to select 'person name' and click 'view' this will display all the current holidays for this person 2)click 'create new' which will bring the user to a create page which allows them to add a new holiday(from here they select person name from drop and and select what date from calender) This all works, however if the user originally follows the first path of selecting a person name and clicking view(it will display their holidays) if they then take the path of 2 and click 'create' it will jump to the create page. however the drop down box will be back at 'select' i would like the existing person selected from the previous drop down to display in this drop down. A cookie or url/parameter? anyway Im stuck please help I've tried a cookie.

    [code]
    [HttpGet]
    public ViewResult Index(string sortOrder, int? currentPersonID)
    {
    var holidays = db.Holidays.Include("Person");
    HolidayList model = new HolidayList();

            if (currentPersonID.HasValue)
            {
                model.currentPersonID = currentPersonID.Value;
    
            }
            else
            {
                model.currentPersonID = 0;
            }
    
            model.PList4DD = db.People.ToList();
    
            //hyperlink to sort dates in ascending order
            ViewBag.NameSortParm = String.IsNullOrEmpty(sortOrder) ? "date" : "";
            var dates = from d in db.Holidays
                        where d.PersonId == currentPersonID.Value    
                        select d;
    
            switch (sortOrder)
            {
                case "date":
                    dates = dates.OrderBy(p => p.HolidayDate);
                    break;
            }
    
            model.HList4DD = dates.ToList();
    
            var cookie = new HttpCookie("cookie\_name", "currentPersonID");
            Response.AppendCookie(cookie);     
    
            return View(model);
        }
    
    public ActionResult Create()
        {
            var cookie = Request.Cookies\["cookie\_name"\];
            if (cookie != null)
            {
                string value = cookie.Value;
                //int? value = cookie.Value;
            }
    
            ViewBag.cookie = cookie.Value;
    
            ViewBag.Id = new SelectList(db.People, "Id", "Name");
            return View();
    

    //tried to use the currentPersonID in index as an int but it wou

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups