Finishing our CRUD

We still have issues in updating and deleting entries.

Let's focus on updating entries, the key idea is retrieve the information from the requested entry and show it on a view page.

Go to Edit Action in the controller class.

  1. We want to get an entry by its corresponding "id" and save it in entry variable.
    Entry entry = _entriesRepository.GetEntry((int)id);
    
  2. Then, we should to check if provided ID is correct or not.
    if(entry == null)
    {
        return HttpNotFound();
    }
    
  3. Finally, just show the view.
    return View(entry)
    
  4. Forgot about one thing, we need to populate the ViewBag of list item. Learn extract method from the instructor (clue: Ctrl + .)
    private void PopulateSelectList()
    {
        ViewBag.SelectListItem = new SelectList(Data.Data.Activities, "Id", "Name");
    }
    

results matching ""

    No results matching ""